crazyone Posted June 28, 2006 Share Posted June 28, 2006 I created a set of class to manage mysql server structure and part of this has two classes used for query and result management. I got a problem storing the result in one of my classes because of the following :It seems PHP is calling the constructor (__construct) then immediatly calling the destructor for no apparent reason... (__destruct). Because of that i can't pass my resource to my constructor because the destructor called immedialty after destroys it. This either forces me to set the result AFTER the creation of the object which is not normal IMO.Is this a normal behavior of PHP5, a bug in the windows binary? I'm running PHP 5.1.2 on a windows 2003 server (Which i doubt is a problem in this case)Here is some code[code]======================================================QUERY FUNCTION======================================================public function query($sql, $buffered = true){ if($this->p_mylink){ //execute the query and look for an exception if($buffered == true){ $res = mysql_query($sql, $this->p_mylink); }else{ $res = mysql_unbuffered_query($sql, $this->p_mylink); } if(is_resource($res)){ //Result returned $mddl_result = new myDDLResult($res); echo 'Completed creation<br><pre>'; var_dump($mddl_result); echo '</pre><br>'; return $mddl_result; //Create a result object and return it }elseif($res === true){ //Command executed succesfully return new myDDLResult(); //Create a result object and return it }elseif($res === false){ //Can only mean an error occured return $this->getError(); //Create a result object and return it }else{ //Impossible case but we'll warn the user throw new myDDLException('query failed to compare mysql_query type'); } } throw new myDDLInvalidOperationException('Not connected to server');}=========================================================RESULT CLASS=========================================================//Class in charge of interfacing a resultfinal class myDDLResult { //Local vars private $p_myresult; //Constructor / destructor public function __construct($result = NULL){ //Store echo 'Creating'; echo '<br>'; var_dump($result); echo '<br>'; $this->p_myresult = $result; } public function __destruct(){ echo 'Destroying'; echo '<br>'; var_dump($this->p_myresult); echo '<br>'; mysql_free_result($this->p_myresult); }}====================================================OUTPUT====================================================Creatingresource(3) of type (mysql result)Destroyingresource(3) of type (mysql result)Completed creationobject(myDDLResult)#1 (1) { ["p_myresult:private"]=> resource(3) of type (Unknown)}Destroyingresource(3) of type (Unknown)Warning: mysql_free_result(): 3 is not a valid MySQL result resource in C:\Source\palliscience\maj.palliscience.com\dev\lib_myddl.php on line 200Destroyingresource(3) of type (Unknown)Warning: mysql_free_result(): 3 is not a valid MySQL result resource in C:\Source\palliscience\maj.palliscience.com\dev\lib_myddl.php on line 200Destroyingresource(3) of type (Unknown)Warning: mysql_free_result(): 3 is not a valid MySQL result resource in C:\Source\palliscience\maj.palliscience.com\dev\lib_myddl.php on line 200Destroyingresource(3) of type (Unknown) [/code] Quote Link to comment https://forums.phpfreaks.com/topic/13136-php-5-objects-and-resources/ Share on other sites More sharing options...
Buyocat Posted June 28, 2006 Share Posted June 28, 2006 Could it be because you're using vardump? Or was this happening before you tried vardump? Also there are several very robust PEAR packages that handle DB abstraction and I strongly suggest you use one of them unless this is a learning experience for you. There really isn't any reason to reinvent the wheel. Quote Link to comment https://forums.phpfreaks.com/topic/13136-php-5-objects-and-resources/#findComment-50511 Share on other sites More sharing options...
crazyone Posted June 28, 2006 Author Share Posted June 28, 2006 [!--quoteo(post=388939:date=Jun 28 2006, 02:43 PM:name=Buyocat)--][div class=\'quotetop\']QUOTE(Buyocat @ Jun 28 2006, 02:43 PM) [snapback]388939[/snapback][/div][div class=\'quotemain\'][!--quotec--]Could it be because you're using vardump? Or was this happening before you tried vardump? Also there are several very robust PEAR packages that handle DB abstraction and I strongly suggest you use one of them unless this is a learning experience for you. There really isn't any reason to reinvent the wheel.[/quote]Nope, it happens on several levels, not just this one, if i put a $this->connect() in my server connection class it also loses my link resource...And don't worry, i'm not reinventing the wheel, i am doing a complete data definition language abstraction layer that doesn't already exist on PEAR. Or else i didn't look correctly last time i went there. Overall i can't find any php5 compatible DDL and DML abstraction library.Back to my problem, what i don't understand is why the __destruct is being called for nothing, i'll try some other tests, can you keep me updated on stuff you try thnks Quote Link to comment https://forums.phpfreaks.com/topic/13136-php-5-objects-and-resources/#findComment-50516 Share on other sites More sharing options...
crazyone Posted June 28, 2006 Author Share Posted June 28, 2006 For all to knowMy previous question was in fact a real PHP bug. This bug is linux AND windows, the problem is caused when you have thezend.ze1_compatibility_mode = Onin the php.ini file. This is a bug that was reported before several times without having been resolved. I commented and reactiveated the bug on the php bug submission engine...Math Quote Link to comment https://forums.phpfreaks.com/topic/13136-php-5-objects-and-resources/#findComment-50556 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.