note 126139 deleted from language.variables.scope by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 19:37:20 +0000 |
| Subject: | note 126139 deleted from language.variables.scope by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217928@lists.php.net to get a copy of this message | ||
Note Submitter: 2505036090 at qq dot com
----
About assignment of object:
```php
<?php
function aaa() {
global $obj;
$cl = new stdclass;
$obj = &$cl; // assign By Ref
$obj->name = 'jack';
$obj = NULL; // the change of $obj leads to the change of $cl
var_dump($cl); // output: NULL
}
aaa();
var_dump($obj); // output: NULL
function bbb() {
global $obj;
$cl = new stdclass;
$obj = $cl; // general assignment of object
$obj->name = 'jack';
$obj = NULL; // the value of $obj changes to NULL, but the value of $cl is still original;
var_dump($cl); //output: object(stdClass)#2 (1) { ["name"]=> string(4)
"jack" }
}
bbb();
var_dump($obj); // output: NULL
?>
```