當前位置:首頁 » 編程語言 » getinstancephp

getinstancephp

發布時間: 2024-10-19 20:50:20

『壹』 如何看待php Strict Standards錯誤

前天無意修改了php.ini關於錯誤輸出的設置,今天測試一個CakePHP開發的項目時竟然發現多了幾條錯誤提示,雖然不是致命的但也不能忽視。

錯誤的描述大概如下

Strict Standards: Redefining already defined constructor for class Object in D:\www\hosts\cake\ucake-libs\cake\libs\object.php on line 69

Strict Standards: Assigning the return value of new by reference is deprecated in D:\www\hosts\cake\ucake-libs\cake\libs\object.php on line 94

Strict Standards: Assigning the return value of new by reference is deprecated in D:\www\hosts\cake\ucake-libs\cake\libs\security.php on line 48

Strict Standards: Assigning the return value of new by reference is deprecated in D:\www\hosts\cake\ucake-libs\cake\libs\inflector.php on line 65

Strict Standards: Assigning the return value of new by reference is deprecated in D:\www\hosts\cake\ucake-libs\cake\libs\configure.php on line 89

Strict Standards: Non-static method Configure::getInstance() should not be called statically in D:\www\hosts\cake\ucake-libs\cake\bootstrap.php on line 43

Strict Standards: Non-static method Configure::write() should not be called statically in D:\www\hosts\cake\ucake-libs\cake\bootstrap.php on line 82

Strict Standards: Non-static method Configure::getInstance() should not be called statically in D:\www\hosts\cake\ucake-libs\cake\libs\configure.php on line 108

大概掃了幾眼,看到基本上是CakePHP框架的錯誤,在Google中搜索相關錯誤信息時發現其它框架也存在這種通病,無耐。。。

只好認真看了看錯誤的解釋,我理解的是:程序沒有按照PHP嚴格規定的模式編寫而給的警告。想到這點於是自己又測試了幾個以前寫的小程序,有的也會出現這個錯誤。看來以後自己得注意自己的編碼規范,不能一味的追求功能…

由於當前項目要進行調試,遂又將php.ini錯誤輸出重新定義為:error_reporting = E_ALL。將E_STRICT去掉了,重啟Apache…一切如常…

『貳』 php里=&是什麼意思

這是引用賦值,應該注意的是 =& 不是一個運算符,不能看成一個整碧數體。
而 &XoopsPreload::getInstance() 應該看成一個整體,相當於運則把XoopsPreload::getInstance()的引用賦值給$xoopsPreload,也就是變數$xoopsPreload是類XoopsPreload實例的一個別名,改變變數$xoopsPreload的值將會改變類XoopsPreload的內部悔悄首值,這應該是一個單例吧。

『叄』 PHP實現單件模式的幾種方式 詳細�0�3

單例模式是我們在開發中經常用到的一種設計模式,利用PHP5 面向對象的特性,我們可以很容易的構建單件模式的應用,下面是單件模式在PHP 中的幾種實現方法: class Stat{ static $instance = NULL; static function getInstance(){ if(self::$instance == NULL){ self::$instance = new Stat(); } return self::$instance; } private function __construct(){ } private function __clone(){ } function sayHi(){ return "The Class is saying hi to u "; } } echo Stat::getInstance()->sayHi(); 這是一種最通常的方式,在一個getInstance 方法中返回唯一的類實例。 對這里例子稍加修改,便可以產生一個通用的方法,只要叫道任何你想用到單件的類里,就可以了。 class Teacher{ function sayHi(){ return "The teacher smiling and said 'Hello '"; } static function getInstance(){ static $instance; if(!isset($instance)){ $c = __CLASS__; $instance = new $c; } return $instance; } } echo Teacher::getInstance()->sayHi(); 最後一種是提供一個singleton 類,然後通過調用getInstance 方法,可以為任何一個類生產出一個實例來。 class singleton{ function getInstance($class){ static $instances = array(); if(!array_key_exists($class,$instances)){ $instances[$class] = &new $class; } $instance = $instances[$class]; return $instance; } } class People{ function sayHi(){ return 'Hello i am a people?'; } } echo "

『肆』 PHP CI框架self::$instance =& $this;

&簡單點可以理解成C語言的& 但是有點差別,$this 實例化的這個類. static instance指向的這個實例.這就是一個單例模式. 所有的代碼 只要調用 classname::getInstance()就可以獲得這個類的實例.

『伍』 php 單例模式

單例模式是一種常用的軟體設計模式,可以保證系統中一個類只有一個實例,從而達到節約系統資源提升特殊類使用效率的目的


php實現單例模式的方法

classA{
//靜態屬性
privatestatic$_instance;

//空的克隆方法,防止被克隆
privatefunction__clone(){}

//獲取實例
(){
if(!(self::$_instanceinstanceofself)){
self::$_instance=newA();
}
returnself::$_instance;
}
}

//調用
$obj=A::getInstance();
熱點內容
戰地5什麼選項吃配置 發布:2024-10-19 23:32:55 瀏覽:528
京存存儲 發布:2024-10-19 23:32:46 瀏覽:192
安卓在哪裡可以下載魔境仙蹤 發布:2024-10-19 23:21:38 瀏覽:656
放量金叉怎麼配置 發布:2024-10-19 23:21:27 瀏覽:456
什麼微信重新找回密碼還是登不上 發布:2024-10-19 23:17:10 瀏覽:167
aj腳本 發布:2024-10-19 23:17:03 瀏覽:125
ftp如何加寬 發布:2024-10-19 23:14:05 瀏覽:678
存儲媒介最新消息 發布:2024-10-19 23:08:11 瀏覽:725
胡樂腳本 發布:2024-10-19 23:08:08 瀏覽:175
亞馬演算法 發布:2024-10-19 22:58:58 瀏覽:922