私は長い間この疑問を抱いていますが、PHPのリファレンスをどのように扱うのが良いアイデアなのですか?例を使用するよりも説明できないので、次のクラスを見てから@ setResultメソッドのコメントPHPのメモリ参照
モデルビューコントローラフレームワークを使用していて、基本的なAjaxControllerを構築しているとしましょう。これまでのところ、1つのアクションメソッド(getUsers)しかありませんでした。コメントを読んで、私の質問がはっきりしていることを願っています.PHPはこのような状況をどのように処理するのですか?setResult docblockのx回について書きました。
class AjaxController{
private $json = array(
'result' => array(),
'errors' => array(),
'debug' => array()
);
/**
* Adds an error, always displayed to users if any errors.
*
* @param type $description
*/
private function addError($description){
$this->json['errors'][] = $description;
}
/**
* Adds an debug message, these are displayed only with DEBUG_MODE.
*
* @param type $description
*/
private function addDebug($description){
$this->json['debug'][] = $description;
}
/**
* QUESTION: How does this go in memory? Cause if I use no references,
* the array would be 3 times in the memory, if the array is big (5000+)
* its pretty much a waste of resources.
*
* 1st time in memory @ model result.
* 2th time in memory @ setResult ($resultSet variable)
* 3th time in memory @ $this->json
*
* @param array $resultSet
*/
private function setResult($resultSet){
$this->json['result'] = $resultSet;
}
/**
* Gets all the users
*/
public function _getUsers(){
$users = new Users();
$this->setResult($users->getUsers());
}
public function __construct(){
if(!DEBUG_MODE && count($this->json['debug']) > 0){
unset($this->json['debug']);
}
if(count($this->json['errors']) > 0){
unset($this->json['errors']);
}
echo json_encode($this->json);
}
}
別の簡単な例:技術Aを使用する方がよいだろうか。
function example(){
$latestRequest = $_SESSION['abc']['test']['abc'];
if($latestRequest === null){
$_SESSION['abc']['test']['abc'] = 'test';
}
}
または技法B:
function example(){
$latestRequest =& $_SESSION['abc']['test']['abc'];
if($latestRequest === null){
$latestRequest = 'test';
}
}
読んでくれてありがとうと助言:)
参考文献に関するPHPマニュアルページ:[http://php.net/manual/en/language.references.php](http://php.net/manual/en/language.references.php) – bfavaretto