Re: php/mysql object id question..

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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...

-bruce


Sounds 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. ;)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux