ID:               48135
 User updated by:  wizanda at yahoo dot co dot uk
 Reported By:      wizanda at yahoo dot co dot uk
-Status:           Feedback
+Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: all
 PHP Version:      5.2.9
 New Comment:

Thank you for the reply, here is a better example and a rephrase of the
problem...
<?php
class Funky{}
class Monkey{}
Class etc{}
function collectClass($name){static $handlers;
if(!isset($handlers[$name])){$handlers[$name] = new $name();
echo 'count<br />';}
var_dump($handlers);
$handle = $handlers[$name];
return $handle;}
collectClass('Funky');
collectClass('Funky');
collectClass('Funky');
?>
On doing this i realized its not so much isset is broken sorry, as if
we test the occurrences of the count, we find it runs once...Yet if we
var_dump() the static var, it has 3 copies of something that it has only
collected once and so shouldn't it only be stored once? Else its
amassing tons of data in a large system?


Previous Comments:
------------------------------------------------------------------------

[2009-05-04 00:42:28] [email protected]

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

We need a self contained script that we can run, though it sounds like
you just need.

!isset($handler, $handler[$name])

To check both the array and the key.

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

[2009-05-03 12:33:15] wizanda at yahoo dot co dot uk

Description:
------------
Since PHP 5 most PHP systems will be storing masses of data, due to
isset and empty no longer assessing the full variable, yet running code
once for each item within it.

Reproduce code:
---------------
---
>From manual page: function.isset
---
function &loadHandler($name){static $handler;
if(!isset($handler[$name])){$FileName = "core/core.".$name.".php";
require_once $FileName;
$ClassName = "SmartyCore_".$name;
$handler[$name] = new $ClassName();}
$classes = $handler[$name];
return $classes;}

Expected result:
----------------
This should check $handler, see if it's empty the first time; check
$name and see this is an empty array, attempt to fill it and thus
setting the $handler as being a container for the array and then check
for each $name as a separate array within it.


Actual result:
--------------
What this appears to be doing is checking $handler and running it, then
checking $name and running it... So when you var_dump the $handler it
has multiple copies of the variable set.
This can be slightly resolved by making the array set the original
$handler variable, which reduces the copies made.
$handler = array($name => new $ClassName());}
...Yet there should be only one copy set.


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


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

Reply via email to