|
Posted by "bruce" on 09/15/05 01:47
it's not my understanding/use of classes.. my issue is that i was blindly
using code that's been used by a lot of people, but that it obviously hadn't
been thoroughly checked!!
but then, i'm starting to realize that there's probably a great deal of
'opensource' code that's in use that hasn't been thoroughly vetted.
when i used to be a software engineer, there's no way in hell that my teams
would have offered some of this up for consumption..
-bruce
lloks like i'm going to need to start remembering/using that which i long
ago tried to forget!!
-----Original Message-----
From: Edward Vermillion [mailto:evermillion@doggydoo.net]
Sent: Wednesday, September 14, 2005 2:46 PM
To: bedouglas@earthlink.net
Cc: php-general@lists.php.net
Subject: Re: [PHP] php/mysql object id question..
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]
|