|
Posted by "bruce" on 09/15/05 00:03
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
-----Original Message-----
From: Stephen Leaf [mailto:smileaf@smileaf.org]
Sent: Wednesday, September 14, 2005 1:51 PM
To: php-general@lists.php.net
Subject: Re: [PHP] php/mysql object id question..
On Wednesday 14 September 2005 03:42 pm, bruce wrote:
> hi...
>
> i have the following psuedo code...
>
> i'm showing the pertinent parts, and eliminating the rest...
>
> ------------------------------------------
> class sql
> {
>
> function sql(...)
> {
> return false
>
> mysql_....
>
> mysql_....
> }
>
> }
>
> $db = new sql(...)
The new sql() is returning an object because that is what your asking for.
now if you did a $db->sql() that'd return false.
yes you did put a return false in the constructor but an object is what is
being created and thus what is being returned. In my opinion a return
anything within the constructor shouldn't be allowed. This might be the
behavior in newer versions but I don't know.
newer syntax is:
class sql {
function __construct (...) {
...
}
}
truthfully when you do the $db = new sql(...); you are not running that
function.. you are instantiating a new instance of sql which is invoking the
object's constructor.
>
> echo "db" = .$db;
> ----------------------------------------
>
> $db comes back as an object id.. even when i force a 'return false'. it
> appears that no matter what i do, the class constructor returns an object
> id!!! the weird thing is that it gets to the 'return false' and then still
> seems to return the 'object id' i've also replaced 'false' with other
> values to see if it made a diff.. it didn't which is good... i would have
> really hit the roof then!!
>
> so.. why is this behavior occuring.
>
> any ideas as to why?
>
> or, am i just too tired right now!
>
> thanks
>
> bruce
>
> ps.. i could use the $db, object ID, and try to see if it actually access
> the db, in order to determine if it actually exists. but i shouldn't have
> to do that... the class should return false!!!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Navigation:
[Reply to this message]
|