note 94394 deleted from function.unset by danbrown

From: Date: Mon, 02 Nov 2009 15:45:47 +0000
Subject: note 94394 deleted from function.unset by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162335@lists.php.net to get a copy of this message
Note Submitter: macnimble at gmail dot com ---- The post from obsidianproject.co.uk is misleading. Typecasting does not set or unset the value of a variable. In example #2, we are simply the var_dump'ing the unset value of $a, which is NULL, but not altering the value of $a, which remains intact. <?php # Example 2 from obsidianproject.co.uk's post $a = "test"; var_dump( (unset) $a ); # NULL # The value of $a remains: var_dump( $a ); # string(4) "test" ?> These tests might help clear it up a bit: <?php error_reporting( E_ALL ); header('Content-Type: text/plain'); $a = "test"; echo "NULL ==> "; var_dump( (unset) $a ); echo 'string(4): "test" ==> '; var_dump( $a ); echo "bool(true) ==> "; var_dump( isset($a) ); echo "bool(false) ==> "; var_dump( is_null($a) ); echo 'string(4): "test" ==> '; var_dump( $a ); $a = "test"; $a = (unset) $a; echo "NULL ==> "; var_dump( $a ); echo "bool(false) ==> "; var_dump( isset($a) ); echo "bool(true) ==> "; var_dump( is_null($a) ); $a = "test"; unset( $a ); echo "bool(false) ==> "; var_dump( isset($a) ); echo "bool(false) (w/notice) ==> "; var_dump( is_null($a) ); ?>

« previous php.notes (#162335) next »