PDA

View Full Version : Cannot access empty property


Jaxel
02-13-2009, 05:13 PM
Fatal error: Cannot access empty property in ...

What does this error mean? I have the following code in one of my functions...

global $vbulletin;

$query = ("SELECT * FROM rank_players
ORDER BY $sort $order, pName ASC");
$result = $vbulletin->$db->query_read($query);

while ($player = $vbulletin->$db->fetch_array($result)) {...}


The table rank_players IS empty, but it should instead simply fail the while loop on line 7; but it never makes it that far and instead dies right on line 5.

Also, what is the difference between $vbulletin->$db-> and $db-> ? Is there a reason to use one over the other?

pein87
02-13-2009, 05:28 PM
I think that $vbulletin is the name of the main class that handels all or most of the queries I havent seen any mods that donet have $vbulletin->$db->. You might look to see if theres a class just called $db and if so see all of its methods and operatiosn to make sure they do what you wont them to.

Jaxel
02-13-2009, 05:52 PM
Well I just changed my above code to the following, and now it works...

global $db;

$query = ("SELECT * FROM rank_players
ORDER BY $sort $order, pName ASC");
$result = $db->query_read($query);

while ($player = $db->fetch_array($result)) {...}

So again... what is the difference between $vbulletin->$db-> and $db-> ? Is there a reason to use one over the other? Why can I sometimes use one and not the other?

pein87
02-13-2009, 05:58 PM
It depends on what your trying to do to understand more you would need to look at the classes themselves to see what each one is capable of doing. Its the same in desktop programming if you make a call to a class but it doesnt support the fuctionality your looking for it will more then likely not work unless you make a if condition to test if it supports what your trying to do. vbulletin is the main class and I'm sure db is made to handel the lesser query tasks.

Dismounted
02-14-2009, 05:19 AM
You will see this in one of the files:
$db =& $vbulletin->db;
They are the same, $db is shorthand for $vbulletin->db. However, $db may not always exist due to scope.