note 126139 added to language.variables.scope
| From: | 2505036090 at qq dot com | Date: | Sat, 05 Jun 2021 01:59:39 +0000 |
| Subject: | note 126139 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216473@lists.php.net to get a copy of this message | ||
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
?>
```
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 222.89.167.20)
----
Manual Page -- https://php.net/manual/en/language.variables.scope.php
Edit -- https://main.php.net/note/edit/126139
Del: integrated -- https://main.php.net/note/delete/126139/integrated
Del: useless -- https://main.php.net/note/delete/126139/useless
Del: bad code -- https://main.php.net/note/delete/126139/bad+code
Del: spam -- https://main.php.net/note/delete/126139/spam
Del: non-english -- https://main.php.net/note/delete/126139/non-english
Del: in docs -- https://main.php.net/note/delete/126139/in+docs
Del: other reasons-- https://main.php.net/note/delete/126139
Reject -- https://main.php.net/note/reject/126139
Search -- https://main.php.net/manage/user-notes.php