was: Bug in implode function, now: bug/missing feature in php/zend

From: Date: Sun, 14 May 2000 12:23:45 +0000
Subject: was: Bug in implode function, now: bug/missing feature in php/zend
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-15000@lists.php.net to get a copy of this message
Reply and extension to post "Bug in implode function ???": I do not think that it is is a bug in the implode() function, rather I think it´s a bug/feature missing in PHP/Zend. ResourceIDs cannot be converted to strings (of course they shouldn´t: ref-counting), they´ll be converted to '' - but sometimes it could be needed to retrieve information about a resource... Initial problem: If you apply implode() to an array containing different variable types, they´re rendered as follows: string,int,double=as is bool= '' for FALSE and 1 for TRUE object='object' array='array' resource id='' I´d expect an empty string for FALSE but not for a ressource id. If a resource id (was integer in php3) cannot be converted to a string, 'resource' should appear, just like 'object' or 'array', the information '' is almost useless... Only 'resource' is (just like 'object' and 'array') of few use. It would be fine to be able to retrieve a unique name (maybe the memory address, which should be unique during script execution) for a resource one could for example log or one could establish caches with. This is function-Cache in a class (works with strings, potentially drains performance obejcts,arrays and ressources): function test($test,$test2) { if (!$this->test[$test][$test2]) { $this->test[$test][$test2]=this->do_foo(); } return $this->test[$test][$test2]; } If working with strings there´s no problem. But working with objects, arrays and especially ressources where more data is present, you will get a problem. If a parameter is a ressource for example, it is captured in $this->test until the whole script is finished or it is unset. My resource will never be freed although there´s reference counting and I do not need the result anymore (I´ve the cached data available) because it´s still present im my $this->test array. Sure, one possibilty could be to free the result manually on a type check, but maybe this is an enhancement others would welcome too and it´s usefull for objects and arrays too. Simplest solution: A function like print_r or var_dump (which worsk with objects,arrays and resources) would be sufficient if it only gives back a result without displaying it or a serialize() function which properly displays a ressource as r:2 or similar and not i:0 . regards, andré

« previous php.version4 (#15000) next »