1

I am doing mostly .NET/Java but now I am doing PHP. I have a class,

class MyClass{
    private $data;
    public function __construct(object $data) {        
        $this->data = $data;
    }
}
class B{

}

echo new MyClass(new B());

When I call this I am getting this error,

Argument 1 passed to MyClass::__construct() must be an instance of object, instance of B given, called in /run_dir/repl.php(56) : eval()'d code on line 11

In C# the super class is object but don't know why its not work in PHP.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Imran Qadir Baksh - Baloch
  • 32,612
  • 68
  • 179
  • 322

0 Answers0