Feed php bir sınıf parametre çalışırken hata oluştu

0 Cevap php

Ben bu gibi sınıflar ilan etti:

class Foo{ public function __construct(){ echo 'Foo was created!';} }

class Foo2 extends Foo{ public function __construct(){ parent::__construct(); echo 'Foo2 was created!';} }

class Bar{
    public function __construct(Foo $foo){ echo 'Bar was created!';}
}

ana kod:

$foo2 = new Foo2();
$bar = new Bar($foo2);

What is reason of this error ana kod:

Fatal hatası: Default value for parameters with a class type hint can only be NULL

php version: PHP 5.3.2

-------------------------------------- Güncellendi! ---------- ------------------------------

Dosya: system.data.php

namespace system\data{

    include ('system.php');

    use system;    
class DBConnection implements system\IDisposable {
    protected $serverName;
    protected $userId;
    protected $password;
    protected $handler;
    protected $isOpened;

    /*
     * create a new instance of DBConnection.
    */
    public function __construct($server, $uid, $password) {
        $this->isOpened = false;
        $this->serverName = $server;
        $this->userId = $uid;
        $this->password = $password;
    }
class DBCommand implements \system\IDisposable {

    public function  __construct(DBConnection $connection, int $type) {
        $this->connection = $connection;
        $this->queryType= $type;
}

}

Dosya: system.data.mysql.php

namespace system\data\mysql{
    class MySqlCommand extends DBCommand {

        public function __construct(data\DBConnection $connection, int $type = 0) {
            parent::__construct($connection, $type);
        }
    }

class MySqlConnection extends DBConnection {

    public function  __construct($server, $uid, $password) {
        parent::__construct($server, $uid, $password);
        }

    }
}

hatası:

Fatal hatası: Default value for parameters with a class type hint can only be NULL in C:\Program Files\Apache Software Foundation\...\system.data.mysql.php on line 35(constructor declartion) 

0 Cevap