Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Fix Strict Standards: Redefining already defined constructor for class

Tags:

php

This error is thrown in PHP 5.4.3, and the solutions I have found was to hide the errors.

error_reporting(E_ALL ^ E_STRICT);

But I want to fix it, not hide it. Could you explain why this error is thrown and how to fix it?

This is the error:

Strict Standards: Redefining already defined constructor for class VisanaObject in /home/template/public_HTML/project/activecollab/angie/classes/VisanaObject.class.php on line 33

This is the code of the class:

class VisanaObject {

    /**
    * Object constructor
    *
    * @param void
    * @return Object
    */
    function VisanaObject() {
      $args = func_get_args();

      // Call constructor, with or without args
      if(is_array($args)) {
        call_user_func_array(array(&$this, '__construct'), $args);
      } else {
        $this->__construct();
      } // if
    } // VisanaObject

    /**
    * Construct the VisanaObject
    *
    * @param void
    * @return VisanaObject
    */
    function __construct() {

    } // __construct

  } // VisanaObject
like image 495
Luis Cardenas Avatar asked Jul 20 '16 18:07

Luis Cardenas


1 Answers

It's a PHP throwback. PHP used the class name as the constructor method, and didn't have a formal __construct() magic method. Now there is __construct, but the "class name as function = constructor" is kept for backwards compatibility.

So you have

class foo {
   function foo() { ... this is a constructor }
   function __construct() { .. this is another constructor ... }
}

Rename your VisanaObject method, or move its code into __construct().

like image 110
Marc B Avatar answered Nov 12 '22 14:11

Marc B