Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Count() throwing errors?

Go to End

2 Posts   1154 Views


SilverStripe Developer, 65 Posts

21 July 2008 at 7:15am


I have about 5 count functions all in the same page controller. They have been working fine for a month or more. Suddenly (without changing the code) the following function crashes the page (with no php-error logs or debug emails being sent)

function CountMembers() {
		$GetMembers = DataObject::get("Member", "", "", "", "");
		$Result = $GetMembers->Count();
		return $Result;

Fairly simple. What could cause it to stop working all of a sudden?



Forum Moderator, 922 Posts

21 July 2008 at 9:51am

Edited: 21/07/2008 10:30am

Well, Count() will probably throw an error on a non-object. A better example would be:

function CountMembers() {
	$members = DataObject::get('Member');
	return $members ? $members->Count() : 0;