note 26015 deleted from language.variables.scope by cmb

From: Date: Sun, 27 Oct 2019 08:33:04 +0000
Subject: note 26015 deleted from language.variables.scope by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212786@lists.php.net to get a copy of this message
Note Submitter: heatwave at fw dot hu ---- Some people (including me) had a problem with defining a long GLOBAL variable list in functions (very error prone). Here is a possible solution. My program parses php file for functions, and compiles GLOBAL variable lists. Then you can just remove from the list those variables which need not be global. <?php //parser for GLOBAL variable list $pfile=file("myfile.php4"); for($i=0;$i<sizeof($pfile);$i++) { if(eregi("function",$pfile[$i])) { list($part1,$part2)=sscanf($pfile[$i],"%s %s"); echo "\n\n $part1 $part2:\nGLOBAL "; $varlist=array(); $level=0; $end=$i; do { $lpar=explode("{",$pfile[$end]); $level+=sizeof($lpar)-1; $lpar=explode("}",$pfile[$end]); $level-=sizeof($lpar)-1; $end++; } while(($end<sizeof($pfile))&&($level>0)); $pstr=""; for($j=$i;$j<=$end;$j++) $pstr.=$pfile[$j]; $lpar=explode("$",$pstr); for($j=1;$j<sizeof($lpar);$j++) { eregi('[a-zA-Z_][a-zA-Z0-9_]*',$lpar[$j],$cvar); $varlist[$cvar[0]]=1; } array_walk($varlist,'var_print'); } } function var_print ($item, $key) { echo "$key,"; } ?>

« previous php.notes (#212786) next »