今天偶然看php 5.3中的一个特性,叫type hinting(类型提示?),感觉怪怪的,看了下,
大概如下,比如有个类:
class Customer {
...
}
class Order {
public function myfunc($c)
{
...
}
}
$o = new Order();
$o->myfunc(xxxxx);
如果myfunc中没规定参数的类型,则可以传不同类型的参数进去,为了规范,假设要传入的是只能customer类的实例,可以这样:
class Customer {
...
}
class Order {
public function myfunc(Customer $c)
{
...
}
}
现在myfunc只能接收Customer类的实例,如果传进去的不是,则报FATAL错了
再看一个例子:
class Type_hint{
function hint_method(array $arr){
print_r($arr);echo "<br/>";
}
}
class Type_hint_new
{
function hint_object(Type_hint $obj){ // Here, If I didn’t pass in an Type_hint object to hint_object(), a FATAL_ERROR was occured.
//echo $obj->hint_method(); // Fatal Error: Argument must be an array
echo $obj->hint_method(array('P','H','P')); //First parameter must be an object of Type_hint class
}
function hint_null($obj = NULL) {
echo "Allow NULL";
}
}
$obj=new type_hint();
$obj_new = new Type_hint_new();
$obj->hint_method(array('b','h','u','m','i'));
$obj_new->hint_object($obj);
$obj_new->hint_null(NULL);
输出:
Array ( [0] => b [1] => h [2] => u [3] => m [4] => i )
Array ( [0] => P [1] => H [2] => P )
Allow NULL
而E_RECOVERABLE_ERROR 这个PHP.INI开关可以设置这个东西
分享到:
相关推荐
项目中要用到zend Optimizer,但是目前只支持php5.2,Ubuntu默认安装的php版本为5.3,找了好多 方法,终于借助下面这篇文章的方法成功的安装了5.2及5.3两个版本的php Although Drupals 7+ run smoothly on PHP 5.3, ...
PHP5.3中文手册,2011年修订的中文帮助文档手册,
php5.3X64位支持win2008r2
最新的版本。可以实现Windows环境下php5.3+apache配置 。
php5.3 64位WampServer 找了很久才找到
php5.3安装版,win32位,线程安全
php_imagick-3.1.2-5.3-nts-vc9-x86 适用于php-5.3-nts-vc9-x86
php5.3版本的wampserver,可以兼容win10
memcache用于PHP5.3非线程版本,好些都是单独版本,全版本的不好找喔。
本人资源中还有很多关于php开发的软件 源码 工具 php扩展等等,希望可以帮到你例如 Linux.chm 成就linux高手 php php-5.4.9.tar.gz php-5.3.19.tar.gz jquery1.8.0 chm 中文手册 jquery1.7.1.chm 中文手册 ...
AIX5.3中使用Java和PHP开发AIX5.3中使用Java和PHP开发AIX5.3中使用Java和PHP开发
(积分会自动改,需要的留言)phpemail 适用php5.3版本,目前github上的phpemail对于5.3好像有不少问题。 实例(含代码):https://blog.csdn.net/github_38854224/article/details/91490084
php-websocket, PHP 5.3的一个简单的PHP web socket实现 PHP web socketweb socket服务器在php中实现。支持 web socket草稿 hybi-10,13 ( 当前用 Chrome 18和 Firefox 11测试) 。支持原点检查。支持各种安全/性能...
lua5.3中文手册 作者 Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes 译者 云风 方便手机和pad看 原址 : http://cloudwu.github.io/lua53doc/manual.html
php5.3版本的php_solr.dll哦,很难找到的哦
x64 php_apc.dll for php5.3.x
PHP5.3入门经典中英文以及源代码资源。 由于资源超过了CSDN上传大小限制,故这里提供网盘下载地址。
windows下php5.3 redis扩展 php_redis.dll
windows版本包含php 5.3,5.4,5.5,5.6 版本
php5.3版本的官方开发文档。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。