在数组对象按引用传递? [英] Are objects in array passed by reference?

查看:85
本文介绍了在数组对象按引用传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在像下面的情况,

class my_class {

    public __construct($params = array()){

        **** do something
    } 

 }

 $other_object = new some_class();

 $object = new my_class(array(
                         'var1' => 'test' 
                         'object' => $other_object));

$ other_object 将被引用或按值传递?

$other_object will be passed by reference or by value?

推荐答案

对象总是引用,除非你克隆它明确。

Objects are always references, except you clone it explicitly.

您可以使用 spl_object_hash() 检索对象ID,然后比较它们彼此。请记住,一旦一个物体被从存储器由垃圾收集移除,ID可以被重用。

You can use spl_object_hash() to retrieve the "object id" and then compare them against each other. Remember, that once an object is removed from the memory by the garbage collector, the ID may get reused.

这篇关于在数组对象按引用传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆