Bug #81123 [Opn->Csd]: Setting a variable in a class to NULL does nothing

From: Date: Thu, 10 Jun 2021 15:33:38 +0000
Subject: Bug #81123 [Opn->Csd]: Setting a variable in a class to NULL does nothing
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234355@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81123&edit=1 ID: 81123 User updated by: jplevene at gmail dot com Reported by: jplevene at gmail dot com Summary: Setting a variable in a class to NULL does nothing -Status: Open +Status: Closed Type: Bug Package: Unknown/Other Function Operating System: Linux & Windows PHP Version: 8.0.7 Block user comment: N Private report: N New Comment: In a simple class I can't reproduce it, but in my larger one it fails 100% of the time. I did a workaround as setting it to false worked fine, so I left it at that. Previous Comments: ------------------------------------------------------------------------ [2021-06-10 15:12:40] jplevene at gmail dot com It's in a far bigger class that I discovered this. I'll run some tests now and get back to you. ------------------------------------------------------------------------ [2021-06-10 14:44:22] imsop@php.net Please ignore the troll, but running your script on an online sandbox doesn't reproduce the problem: https://3v4l.org/POdHF (I've switched to var_dump just because it shows the difference between NULL and false more clearly). Does running that exact code on your local install gives a different result, or is there some other code that's interacting in some way? ------------------------------------------------------------------------ [2021-06-10 14:27:38] rtrtrtrtrt at dfdfdfdf dot dfd is it *really* that hard to provide a *full working* reproducer instead some useless comments? your comments are simply not true [user@localhost:/downloads]$ cat test.php <?php $test = new myClass; $test->func(); class myClass { private $var = null; function __construct() { $this->var = "Hello"; } public function func() { $this->var = null; // Does nothing, still "Hello" echo $this->var, "\n"; unset($this->var); // Does nothing, still "Hello" echo $this->var, "\n"; $this->var = false; // Works } } [user@localhost:/downloads]$ php test.php Notice: Undefined property: myClass::$var in /mnt/data/downloads/test.php on line 16 [user@localhost:/downloads]$ ------------------------------------------------------------------------ [2021-06-10 14:22:21] jplevene at gmail dot com public function func() { $this->var = null; print_r($this->var);// Does nothing, still "Hello" unset($this->var); print_r($this->var);// Does nothing, still "Hello" $this->var = false; print_r($this->var);// Works and prints "Hello" } ------------------------------------------------------------------------ [2021-06-10 13:13:00] nikic@php.net How did you determine that the value is still "Hello"? Please provide a complete example which also shows the incorrect result. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=81123 -- Edit this bug report at https://bugs.php.net/bug.php?id=81123&edit=1

« previous php.bugs (#234355) next »