ID:               27358
 User updated by:  mail at iaindooley dot com
 Reported By:      mail at iaindooley dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Variables related
 Operating System: FreeBSD 4.7
 PHP Version:      4.3.4
 New Comment:

crazy pills. no bug. sorry... long live PHP!


Previous Comments:
------------------------------------------------------------------------

[2004-02-23 00:05:11] mail at iaindooley dot com

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 this bug report at http://bugs.php.net/?id=27358&edit=1

Reply via email to