当前位置:首页 » 编程语言 » 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();
热点内容
安卓在哪里可以下载魔境仙踪 发布:2024-10-19 23:21:38 浏览:655
放量金叉怎么配置 发布:2024-10-19 23:21:27 浏览:455
什么微信重新找回密码还是登不上 发布:2024-10-19 23:17:10 浏览:166
aj脚本 发布:2024-10-19 23:17:03 浏览:124
ftp如何加宽 发布:2024-10-19 23:14:05 浏览:677
存储媒介最新消息 发布:2024-10-19 23:08:11 浏览:724
胡乐脚本 发布:2024-10-19 23:08:08 浏览:174
亚马算法 发布:2024-10-19 22:58:58 浏览:921
数据库博士 发布:2024-10-19 22:53:15 浏览:902
班云服务器软件 发布:2024-10-19 22:15:26 浏览:527