note 62581 rejected from function.mysql-fetch-object by betz

From: Date: Sat, 04 Mar 2006 01:23:23 +0000
Subject: note 62581 rejected from function.mysql-fetch-object by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-104809@lists.php.net to get a copy of this message
Note Submitter: andrew at majiclab dot com ---- 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...

« previous php.notes (#104809) next »