开发者

PHP - OOP new class with agrument?

开发者 https://www.devze.com 2023-01-16 08:50 出处:网络
class Dictionary { private $translations = array(); private $dictio; private $type; function __construct( $type, DictionaryIO $dictio ) {
class Dictionary {
    private $translations = array();
    private $dictio;
    private $type;

    function __construct( $type, DictionaryIO $dictio ) {
        $this->type = $type;
        $this->dictio = $dictio;
  开发者_如何学C  }

    // ...
}

$en = new Dictionary( "En", new DictionaryIO() );
$en->dictio = null;

i saw something like above code. Someone can tell me effective of line code

$en = new Dictionary( "En", new DictionaryIO() );


Someone can tell me effective of line code

A new object of the class Dictionary is created. The two arguments are passed to the constructor function, which stores them internally.

The DictionaryIO prefix in front of DictionaryIO $dictio is a so called type hint that forces the second parameter to be an object of the class DictionaryIO.

The last line

$en->dictio = null;

will not work because $dictio is private.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号