note 62581 added to function.mysql-fetch-object

From: Date: Fri, 03 Mar 2006 20:27:12 +0000
Subject: note 62581 added to function.mysql-fetch-object
Groups: php.notes 
Request: Send a blank email to php-notes+get-104789@lists.php.net to get a copy of this message
Apparently mysql_fetch_object has a secret second argument (at least in PHP 5.1.2), which does what so many people want it to do — creates an instance of a class. I discovered this by accident where some old code was calling mysql_fetch_object() but it apparently used to call mysql_fetch_array(), as the second paramter was MYSQL_ASSOC. Well, all of a sudden I got an error saying "Class 1 not found". !?!?!? Well, when I found out that the second argument was in fact not supposed to be there, I removed it, and my error was gone. But that made me wonder, "what if I put an existing class name in there instead?". So I tried this: $oRow = mysql_fetch_object($result, 'testClass'); And voilà, it was an instance of that class!! Again, this is in PHP 5.1.2, have no idea when this was implemented because this code used to work fine on a PHP4 system... ---- Server IP: 66.207.199.35 Probable Submitter: 68.146.113.232 ---- X-Spam-Status: Yes, hits=7.4 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HEAD_ILLEGAL_CHARS autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-object.php Edit -- http://master.php.net/note/edit/62581 Del: integrated -- http://master.php.net/note/delete/62581/integrated Del: useless -- http://master.php.net/note/delete/62581/useless Del: bad code -- http://master.php.net/note/delete/62581/bad+code Del: spam -- http://master.php.net/note/delete/62581/spam Del: non-english -- http://master.php.net/note/delete/62581/non-english Del: in docs -- http://master.php.net/note/delete/62581/in+docs Del: other reasons-- http://master.php.net/note/delete/62581 Reject -- http://master.php.net/note/reject/62581 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#104789) next »