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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   1218 Views

Avatar
Josh

SilverStripe Developer, 65 Posts

21 July 2008 at 7:15am

Hi,

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?

:)

Avatar
Sean

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;
}

Sean