Fatal Error:Call to a member function count() on a non-object

I made the rookie mistake of starting my project in windows and migrating it to unbuntu. This move was forced upon me and resulted in a lot of unintended consequences. It generated a lot of errors one being fatal.

I know that the object is not null by simply doing a var_dump.Inside the var_dump the method is there. So my question: Why would this work flawlessly in a windows environment and not in the linux environment. I went through the code and fixed all my capitalization issues I think.

The code that generates the error is:

public function find($user = null) {
if ($user) {
$field = (is_numeric($user)) ? ‘id’ : ‘username’;

        $data = $this->_db->get('user', array($field, '=', $user));
         var_dump($data);
        if ($data->count()) {
            $this->_data = $data->first();
            return true;
        }
    }

var_dump($data);
object(DB)#3 (6) { ["_pdo":“DB”:private]=> object(PDO)#4 (0) { } ["_query":“DB”:private]=> object(PDOStatement)#5 (1) { [“queryString”]=> string(31) “SELECT * FROM user WHERE id = ?” } ["_error":“DB”:private]=> bool(false) ["_result":“DB”:private]=> array(1) { [0]=> object(stdClass)#6 (8) { [“id”]=> string(2) “39” [“username”]=> string(8) “test1234” [“password”]=> string(64) “d1dcebd95402062c466eeb1e2b5e6c3b217a0fe160bc3baac86bafc9613494e9” [“salt”]=> string(32) “.JMs.ˆ~ìdÿ)7Ð §FKS¨Ê×$'å¹Yˆc¥” [“name”]=> string(0) “” [“joined”]=> string(10) “2014-11-20” [“disabled”]=> string(1) “0” [“email”]=> string(18) "[email protected]" } } ["_count":“DB”:private]=> int(1) [“error”]=> bool(false) }

    return false;
}

If I had to guess, I would say that maybe your windows was one version of PHP and the unbuntu was running another version of PHP. For example maybe windows was running PHP 5.2 and unbuntu PHP 5.5? So there might be an obsolete function/method that needs to be converted or PHP Version upgraded (or downgraded)? Is there any way to test this on a web server, instead of a local server? That might give a good indication on what’s happening. I know that it has happen to me, but not exactly like you. I would test it thoroughly on the local server and then throw it on the web server. Then to my dismay the script won’t work. Sometimes it’s the PHP version and other times it the environments (Windows -vs- Linux). The latter is the more frustrating; however, I think once you solve the problem, it should be clear sailing for you be running an OS that is closer to the web server than Windoze. :slight_smile: Another I would do is check the methods, check to see if they public or utilize setters/getters that retrieves protected/private variables? That might be the problem? I’m sure others will give you other possible solutions or ideas to a possible solution.

DUPLICATE POST OF

http://www.phphelp.com/forum/beginners-learning-php/call-to-a-member-function-count-on-a-non-object-po/msg85746/?topicseen#msg85746

Sponsor our Newsletter | Privacy Policy | Terms of Service