Bug #81123 [Com]: Setting a variable in a class to NULL does nothing

From: Date: Thu, 10 Jun 2021 13:13:37 +0000
Subject: Bug #81123 [Com]: Setting a variable in a class to NULL does nothing
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234347@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
 Comment by:         rtrtrtrtrt at dfdfdfdf dot dfd
 Reported by:        jplevene at gmail dot com
 Summary:            Setting a variable in a class to NULL does nothing
 Status:             Feedback
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   Linux & Windows
 PHP Version:        8.0.7
 Block user comment: N
 Private report:     N

 New Comment:

you *decalre* the variable with NULL
you set it to "Hello" in __construct()
why in the world do you expect it should stay at NULL

> Variable stays as "Hello"

nonsense, you SET IT to "Hello"


Previous Comments:
------------------------------------------------------------------------
[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.

------------------------------------------------------------------------
[2021-06-10 13:10:32] jplevene at gmail dot com

Description:
------------
A declared variable in a class can't be set to NULL or unset

Test script:
---------------
class myClass {
	private $var = null;

	function __construct() {
		$this->var = "Hello";
	}

	public function func()
	{
		$this->var = null;  // Does nothing, still "Hello"
		unset($this->var);  // Does nothing, still "Hello"
		$this->var = false; // Works
	}
}

Expected result:
----------------
Variable should be null

Actual result:
--------------
Variable stays as "Hello"


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=81123&edit=1


Thread (10 messages)

« previous php.bugs (#234347) next »