Re: php/mysql object id question..
| From: | Edward Vermillion | Date: | Wed, 14 Sep 2005 21:45:40 +0000 |
| Subject: | Re: php/mysql object id question.. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-222426@lists.php.net to get a copy of this message | ||
bruce wrote:
stephen, you're correct regarding what's going on... i had taken some code used in phpBB, and blindly slammed it into my app to test out their db class... i had assumed that it worked!!!! guess what!!! in their constructor, they have the 'return false' arrggghh!!! a quick look at google, and it appears that you can't return any val from a constructor. in fact, the 'object id' that's being returned appears to simply be (as you stated) the instance of the class that was created... as opposed to a return val... thoughts/comments/etc... -bruceSounds like a good thing to me. What would happen to your code if the constructor returned false? How would you handle it? And why would you want it to in the first place? The return from a = new Class(); should be an object as you're assigning it to a variable that is supposed to represent the object. If your doing something in the constructor that might return false, then set a property in the class to false and check that. IE for a database class if you set up your connection in the constructor then do a <psudocode> if(!mysql_connect...){ $this->connected = false; } </psudocode> and then check $db->connected after a $db = new DB(); or whatever your doing. Don't get me wrong, I had a lot of return false;'s in my constructors before I found out you can't do that, then started to wonder why I would want to. ;)