You are here: Re: [PHP] php/mysql object id question.. « PHP « IT news, forums, messages
Re: [PHP] php/mysql object id question..

Posted by Edward Vermillion on 09/15/05 00:45

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация