#48135 [Bgs]: Isset doesn't function as expected

2009-05-11 Thread wizanda at yahoo dot co dot uk
 ID:   48135
 User updated by:  wizanda at yahoo dot co dot uk
 Reported By:  wizanda at yahoo dot co dot uk
 Status:   Bogus
 Bug Type: Feature/Change Request
 Operating System: all
 PHP Version:  5.2.9
 New Comment:

Since this is a major issue, still waiting for some response, though
I've now changed most static questions to be returned before it
overfills, there are numerous PHP examples and projects all not knowing
this.
Please test it more carefully as it basically means PHP is a memory
hog, when it doesn't need to be.


Previous Comments:


[2009-05-04 12:23:29] wizanda at yahoo dot co dot uk

There are two scripts there...
The first has shown multiple copies on a fresh install of WAMP, and on
my webserver.
This same principle is similar to a singleton pattern and can be also
tested in these. Even on a single variable with no array, if multiple
copies of a class instance are called; When we var_dump() the static
variable, it has multiples of the class object, and thus its not
single
To make it single, as a solution to the static variables holding to
much data, the second script shows that if it's set we return it;
Thus only allowing the one copy of the class object, within the static
variable.



[2009-05-04 11:28:06] scott...@php.net

I can't reproduce this, the output I get is as follows:

scott-mbp:tmp scott$ /usr/bin/php test.php
countbr /array(1) {
  [Funky]=
  object(Funky)#1 (0) {
  }
}




[2009-05-04 11:12:27] wizanda at yahoo dot co dot uk

Found that if you return it first when it's set, it won't multiple fill
the static var, yet this is also the same as a singleton pattern, so it
looks as if those are also mass storing information.
?php
class Funky{}
class Monkey{}
Class etc{}
function collectClass($name){static $handlers;
if(isset($handlers[$name])){$handle = $handlers[$name];
return $handle;}else{$handlers[$name] = new $name();
echo 'countbr /';}
var_dump($handlers);
$handle = $handlers[$name];
return $handle;}
collectClass('Funky');
collectClass('Funky');
collectClass('Funky');
?



[2009-05-04 09:45:34] wizanda at yahoo dot co dot uk

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 'countbr /';}
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?



[2009-05-04 00:42:28] scott...@php.net

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.



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/48135

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



#48135 [Bgs]: Isset doesn't function as expected

2009-05-04 Thread wizanda at yahoo dot co dot uk
 ID:   48135
 User updated by:  wizanda at yahoo dot co dot uk
 Reported By:  wizanda at yahoo dot co dot uk
 Status:   Bogus
 Bug Type: Feature/Change Request
 Operating System: all
 PHP Version:  5.2.9
 New Comment:

There are two scripts there...
The first has shown multiple copies on a fresh install of WAMP, and on
my webserver.
This same principle is similar to a singleton pattern and can be also
tested in these. Even on a single variable with no array, if multiple
copies of a class instance are called; When we var_dump() the static
variable, it has multiples of the class object, and thus its not
single
To make it single, as a solution to the static variables holding to
much data, the second script shows that if it's set we return it;
Thus only allowing the one copy of the class object, within the static
variable.


Previous Comments:


[2009-05-04 11:28:06] scott...@php.net

I can't reproduce this, the output I get is as follows:

scott-mbp:tmp scott$ /usr/bin/php test.php
countbr /array(1) {
  [Funky]=
  object(Funky)#1 (0) {
  }
}




[2009-05-04 11:12:27] wizanda at yahoo dot co dot uk

Found that if you return it first when it's set, it won't multiple fill
the static var, yet this is also the same as a singleton pattern, so it
looks as if those are also mass storing information.
?php
class Funky{}
class Monkey{}
Class etc{}
function collectClass($name){static $handlers;
if(isset($handlers[$name])){$handle = $handlers[$name];
return $handle;}else{$handlers[$name] = new $name();
echo 'countbr /';}
var_dump($handlers);
$handle = $handlers[$name];
return $handle;}
collectClass('Funky');
collectClass('Funky');
collectClass('Funky');
?



[2009-05-04 09:45:34] wizanda at yahoo dot co dot uk

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 'countbr /';}
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?



[2009-05-04 00:42:28] scott...@php.net

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=48135edit=1