note 113115 added to language.variables.scope

From: Date: Sat, 31 Aug 2013 21:27:06 +0000
Subject: note 113115 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-196135@lists.php.net to get a copy of this message
<?php // if you really want to create a variable within its own scope // that does not have access to variables outside its scope create a function $var = "hello"; $func = function(){ // declare variables here that will only last throughout this scope if( !isset($var) ) // var will not be set in this scope { $var = "i was out of scope"; } echo $var; }; echo "$var<br />"; $func(); // invoke the function echo "<br />".'$var'." never changed from $var"; ?> outputs : hello i was out of scope $var never changed from hello ---- Server IP: 69.147.83.199 Probable Submitter: 98.176.50.73 ---- Manual Page -- http://php.net/manual/en/language.variables.scope.php Edit -- https://master.php.net/note/edit/113115 Del: integrated -- https://master.php.net/note/delete/113115/integrated Del: useless -- https://master.php.net/note/delete/113115/useless Del: bad code -- https://master.php.net/note/delete/113115/bad+code Del: spam -- https://master.php.net/note/delete/113115/spam Del: non-english -- https://master.php.net/note/delete/113115/non-english Del: in docs -- https://master.php.net/note/delete/113115/in+docs Del: other reasons-- https://master.php.net/note/delete/113115 Reject -- https://master.php.net/note/reject/113115 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#196135) next »