Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Count() throwing errors?

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

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

Page: 1
Go to End
Author Topic: 952 Views
  • Josh
    Avatar
    SilverStripe Developer
    65 Posts

    Count() throwing errors? Link to this post

    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?

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Count() throwing errors? Link to this post

    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

    952 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.