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.

Archive /

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

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

Count() throwing errors?


Reply


2 Posts   1005 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