#27358 [NEW]: Variable assignment produces errors

From: Date: Mon, 23 Feb 2004 05:05:12 +0000
Subject: #27358 [NEW]: Variable assignment produces errors
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-55348@lists.php.net to get a copy of this message
From:             mail at iaindooley dot com
Operating system: FreeBSD 4.7
PHP version:      4.3.4
PHP Bug Type:     Variables related
Bug description:  Variable assignment produces errors

Description:
------------
i'm sorry if this bug report sounds strange, but this is a very strange
bug. if it is indeed a bug. a problem with this is that in order to
reproduce the bug you would have to install all the ancestor classes to
run the code, but i think you will get a good idea of what is going wrong
from my description below. basically, this method is part of a
DBSelectQuery class that is just a convenience class for building database
queries on the fly. The particular method in question is being used in
many many other places without errors.

Reproduce code:
---------------
        /**
        * Add a clause to this query
        * @param clause - a DBClause object
        */
        function setClause($db_clause)
        {
            if($db_clause!="")
            {
                $str = $db_clause->toString();
                $this->clause = $str;
            }
        }

Expected result:
----------------
the expected result would be that the member variable 'clause' of the
query object would now have the value of the $db_clause object's
toString() method.

Actual result:
--------------
if the code is executed as it is above, i get the error:

Fatal error: Call to a member function on a non-object in
/usr/home/iain/public_html/sitekitchen/classes/db/dbselectquery.class.inc
on line 101

Line 101 is the line with the call:

$str = $db_clause->toString();

So one would assume that $db_clause is somehow not an object. However, if
i comment out the line that assigns the variable $str to $this->clause,
then there is no error. ie. the code now looks like this:

        /**
        * Add a clause to this query
        * @param clause - a DBClause object
        */
        function setClause($db_clause)
        {
            if($db_clause!="")
            {
                $str = $db_clause->toString();
echo($str);
                //$this->clause = $str;
            }
        }

And i get the following printed out to the screen:

WHERE functionid = '34' 

which is the expected result of the $db_clause object's toString() method,
so it is clearly an object.

Please bare in mind here, that the 'Call to a member function on a
non-object" error is _not_ occuring on the line that i have commented out
above. Commenting out this line prevents the error from occuring in the
_previous_ line!!!

also, if i assign some other random string to $this->clause, ie. the code
now looks like this:

        /**
        * Add a clause to this query
        * @param clause - a DBClause object
        */
        function setClause($db_clause)
        {
            if($db_clause!="")
            {
                $str = $db_clause->toString();
echo($str);
                $this->clause = "some random string";
            }
        }

then the code is fine (apart from the fact that the database query doesn't
work because it has the words "some random string" instead of a where
clause!)

i am also able to assign the variable $str to some other random variable,
ie:

        /**
        * Add a clause to this query
        * @param clause - a DBClause object
        */
        function setClause($db_clause)
        {
            if($db_clause!="")
            {
                $str = $db_clause->toString();
                $some_random_variable = $str;
echo($str."<br>".$some_random_variable);
                $this->clause = "some random string";
            }
        }

this gives the expected output:

WHERE functionid = '34'
WHERE functionid = '34'

i seriously feel like i am taking crazy pills. if you need some more info,
let me know.

-- 
Edit bug report at http://bugs.php.net/?id=27358&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27358&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27358&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27358&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27358&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27358&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27358&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27358&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27358&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27358&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27358&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27358&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27358&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27358&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27358&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27358&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27358&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27358&r=float


Thread (2 messages)

« previous php.bugs (#55348) next »