Php dize bir değer türüdür?

0 Cevap php

Neden PHP dize bir değer türüdür? Her yerde argümanı bir işleve geçirilen her zaman kopyalanır, atama yapılan her zaman, her birleştirme dize kopyalanmasına neden olur. Benim. NET deneyim verimsiz görünüyor ve hemen hemen her yerde başvuruları kullanmak için beni zorlar söylüyor. Aşağıdaki alternatifleri göz önünde bulundurun:

Alternatif 1

// This implementation hurts performance
class X {
    public $str;
    function __construct($str) { // string copied during argument pass
        $this->$str = $str; // string copied here during assignment
    }
}

Alternatif 2

// This implementation hurts security
class Y {
    public $str;
    function __construct(&$str) {
        $this->$str = &$str;
    }
}
// because
$var = 'var';
$y = new Y($var);
$var[0] = 'Y';
echo $y->var; // shows 'Yar'

Alternatif 3

// This implementation is a potential solution, the callee decides
// whether to pass the argument by reference or by value, but
// unfortunately it is considered 'deprecated'
class Z {
    public $str;
    function __construct($str) {
        $this->$str = &$str;
    }
}
// but
$var = 'var';
$z = new Z(&$var); // warning jumps out here
$var[0] = 'Z';
echo $y->var; // shows 'Zar'

Soru: Ne acı ben seçmeliyim performans / Güvenlik / İtiraz

0 Cevap