Table of Contents
回复讨论(解决方案)

对象引用问题

Jun 23, 2016 pm 01:50 PM
object Quote

class A{	public $foo = 1;}$a = new A();$b = $a;$b->foo = 2;echo $a->foo . "<br />";$c = new A();$d = & $c;$d->foo = 3;echo $c->foo;
Copy after login

$b=$a 和 $d=&$c 有什么区别啊,这里用不用 & 都没什么不同


回复讨论(解决方案)

= 传值
=& 传引用
对象总是以 引用 传递的
所以对于对象 = 和 =& 没有区别

= 传值
=& 传引用
对象总是以 引用 传递的
所以对于对象 = 和 =& 没有区别


今天再看发现不对劲,但应该是有区别的吧?
<?phpclass A{}$a = new A();$b = &$a;$c = $a;$a = null;var_dump($a);var_dump($b);var_dump($c);
Copy after login

输出:NULL NULL object(A)#1 (0) { }
$c也应该为null才对啊??

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use block quotes in Apple Notes How to use block quotes in Apple Notes Oct 12, 2023 pm 11:49 PM

How to use block quotes in Apple Notes

Convert an array or object to a JSON string using PHP's json_encode() function Convert an array or object to a JSON string using PHP's json_encode() function Nov 03, 2023 pm 03:30 PM

Convert an array or object to a JSON string using PHP's json_encode() function

C++ compilation error: undefined reference, how to solve it? C++ compilation error: undefined reference, how to solve it? Aug 21, 2023 pm 08:52 PM

C++ compilation error: undefined reference, how to solve it?

What is the Request object in PHP? What is the Request object in PHP? Feb 27, 2024 pm 09:06 PM

What is the Request object in PHP?

How to convert MySQL query result array to object? How to convert MySQL query result array to object? Apr 29, 2024 pm 01:09 PM

How to convert MySQL query result array to object?

What are the benefits of C++ functions returning reference types? What are the benefits of C++ functions returning reference types? Apr 20, 2024 pm 09:12 PM

What are the benefits of C++ functions returning reference types?

Use Python's __contains__() function to define the containment operation of an object Use Python's __contains__() function to define the containment operation of an object Aug 22, 2023 pm 04:23 PM

Use Python's __contains__() function to define the containment operation of an object

Use Python's __le__() function to define a less than or equal comparison of two objects Use Python's __le__() function to define a less than or equal comparison of two objects Aug 21, 2023 pm 09:29 PM

Use Python's __le__() function to define a less than or equal comparison of two objects

See all articles