php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27358 Variable assignment produces errors
Submitted: 2004-02-23 00:05 UTC Modified: 2004-02-23 08:17 UTC
From: mail at iaindooley dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.3.4 OS: FreeBSD 4.7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mail at iaindooley dot com
New email:
PHP Version: OS:

 

 [2004-02-23 00:05 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-23 08:17 UTC] mail at iaindooley dot com
crazy pills. no bug. sorry... long live PHP!
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jan 02 14:01:28 2025 UTC