Search code examples
phpstandardsstrict

PHP Strict Standards: Creating default object from empty value


i have this error in my cronjobs report

PHP Strict Standards: Creating default object from empty value in /home/admin/domains/DOMAIN.com/public_html/birthdate.php on line 28 Strict Standards: Creating default object from empty value in /home/admin/domains/DOMAIN.com/public_html/birthdate.php on line 28

And My Codes :

28-   $D->user_birthdate = array();
29-   $latest_members_arr = $network->get_user_birthdate();
30-   foreach($latest_members_arr as $usr)
40-   {
41-     $D->user_birthdate[]    = $network->get_user_by_id($usr);
42-   }
43-    $num    = 30;
44-   $D->user_birthdate    = array_slice($D->user_birthdate, 0, $num);

How can i fix this problem?


Solution

  • At the top of your code add the below line.

    $D =  new stdClass();
    $D->user_birthdate = array();
    

    You get the error because $D doesn't exist. You should create a new StdClass object. stdClass is php's generic empty class. Read more.

    Given that if your $D object has a specific type(type of object) make sure you use it. EG :

    $D =  new dClass();
    

    Here $D is a object of Class dClass()