2012-11-24 4 views
-1

가능한 중복 :
Reference - What does this symbol mean in PHP?PHP는 특별한 표기

내가 개체 초기화에 사용되는 다음과 같은 특수 표기 을 발견 this tutorial .There를 사용하여 PHP MVC를 공부하고

$this->$model =& new $model; 

나는 &을 알고있다. r은 앰퍼샌드 (&)를 HTML로 표현합니다. 여기서 의미하는 것은 무엇입니까? 표기법이있는 클래스가 아래에 주어져 있습니다. 또한이 튜토리얼은 무엇입니까? 좋은 사람입니까? 다른 사람이 나를 더 잘 참조 할 수 없다면 하나?

<?php 
class Controller { 

    protected $_model; 
    protected $_controller; 
    protected $_action; 
    protected $_template; 

    function __construct($model, $controller, $action) { 

     $this->_controller = $controller; 
     $this->_action = $action; 
     $this->_model = $model; 

     $this->$model =&amp; new $model; 
     $this->_template =&amp; new Template($controller,$action); 

    } 

    function set($name,$value) { 
     $this->_template->set($name,$value); 
    } 

    function __destruct() { 
      $this->_template->render(); 
    } 

}

+0

그게 나에게 유효한 PHP 같지 않아. 실행하면 오류나 경고가 발생합니까? – Dai

+5

더 나은 자습서를 찾으십시오. '$ variable = & new Something'은 PHP 4의 나머지 부분이며, PHP 5에서는 필요 없습니다. mysql_ * 함수는 새로운 코드에서는 사용하지 말아야합니다 *. 'register_globals'와'magic_quotes_gpc' 같은 것들도 마찬가지입니다. – DCoder

+0

나에게 좋은 자습서를 제안 해 줄 수 있습니까? –

답변

2

&amp; translates to &은 그래서 참조로 할당 될 것이다. (DCoders 코멘트에 의해).
실제로해야 당신이보고있다 : 어떤 PHP5에 그 주장되지만

$this->$model =& new $model; 

And =& in php relates to passing something by reference.

가 필요없는 (그리고 동의) 정확히 같은 일 아니다 그것은있을 수 있습니다 알고 helpfull ...의 키 포인트

하나 (수동)에서

종종 언급되는 PHP 5 OOP는 ""객체가 기본적으로 참조에 의해 전달된다는 것입니다. 이것은 완전히 이 아닙니다. 객체에 사용

이러한 문맥에
+0

개체가 아닌 함수에 대한 참조로 전달하지 않습니까? –

+1

@PRPGFerret, 설명서에는 http://php.net/manual/en/language.oop5.references.php – Frankie

+2

에 대한 설명이 있습니다. [* 할당 기준 *] (http://us.php.net /manual/en/language.references.whatdo.php#language.references.whatdo.assign), 참조로 전달하지 않음 *. – DCoder

0

은 PHP

에서
$a = &$b 

수단 참조 값을 전달한다. 버전 5의 PHP에서 모든 객체는 기본적으로 참조로 전달됩니다. 그럼 그냥 건너 뛸 수 & 기호

$a = new b();