有事没事,看看 PHP,新语言特性总是不断出现,函数实现也总有新发现;在引入 Laravel 过程中,给我们不少新启示;PHP 导航搜索功能 做得不错;
- 3v4l.org: The best online PHP shell, that allows you to run your code on that server. 非常好,随时可以试验一些语言特性,感谢站主。
- Are parent constructors called if a child class does NOT define a constructor?
- $new = new self($data); with private functions and even variables oO? 在类定义的内部 new 出来的本类对象,可以直接访问 private 数据成员和成员函数。可访问性(accessibility)其本意是对其他类隐藏本类的实现细节。官方文档对此说法是 Objects of the same type will have access to each others private and protected members even though they are not the same instances.(Visibility from other objects)
- 在 PHP 中,整数字节数是平台相关的,现在通常已经是 8 字节(64位)了。
你可以通过php -r 'echo PHP_INT_SIZE;'
查看;其中-r <code> Run PHP <code> without using script tags <?..?>
。
http://tech.qq.com/a/20161205/018335.htm?pgv_ref=aio2015&ptlang=2052
http://www.phptherightway.com/pages/Functional-Programming.html
https://www.christophh.net/2011/10/26/closure-object-binding-in-php-54/
http://stackoverflow.com/questions/11592268/php-the-closure-class
https://phpocean.com/tutorials/back-end/a-takeover-of-php-closure-and-anonymous-functions/49
http://stackoverflow.com/questions/4535330/calling-closure-assigned-to-object-property-directly
http://codesamplez.com/programming/php-closure-tutorial
http://culttt.com/2013/03/25/what-are-php-lambdas-and-closures/
http://stackoverflow.com/questions/2412299/why-and-how-do-you-use-anonymous-functions-in-php
http://stackoverflow.com/questions/4147400/why-use-anonymous-function
http://fabien.potencier.org/on-php-5-3-lambda-functions-and-closures.html
http://eddmann.com/posts/using-anonymous-functions-lambdas-and-closures-in-php/
https://docs.hhvm.com/hack/lambdas/introduction
http://www.phptherightway.com/pages/Functional-Programming.html
http://www.jianshu.com/p/a2d23fb7e34f
http://www.jianshu.com/p/409e118583d9
- get_called_class()
The function get_called_class() is intended for static methods.
区别于__class__
,self::
,static::
,static::class
,get_class()
;相对来说,static::class
含义更明确;static::
是运行时计算的; - class alias
-
get_object_vars()
Gets the accessible non-static properties of the given object according to scope. -
var_dump()
对照 get_object_vars 看,var_dump 可查看所有属性:All public, private and protected properties of objects; - gettype();
-
call_user_func()
call function,class method,lambda-stylish;可以指定 namespace;
call_user_func_array();
在递归函数 recursive function 中使用 call_user_func;
function Factorial($i=1) { return ($i==1?1:$i*call_user_func(__FUNCTION__,$i-1));}
通常:function,variable function, call_user_func, eval,速度递减;
匿名函数(Anonymous functions)
- Anonymous function 是相对于你熟悉的 regular function 来说的;
- 匿名函数是一个表达式 expressions;而普通函数是 code constructs;
- 匿名函数可赋值给变量,以备后续调用;
- 匿名函数作为 callback 参数,代码简洁 ;
preg_replace_callback,PCRE Patterns,regex101;usort; - 匿名函数用来创建 closure,代码简洁;
A closure encapsulates its scope, meaning that it has no access to the scope in which it is defined or executed.
It is, however, possible to inherit variables from the parent scope (where the closure is defined) into the closure with the use keyword.
A closure is a function that retains access to the variables in its enclosing scope, even if that scope has since disappeared.
匿名函数作为返回值返回; - PHP Anonymous Functions: What Are They, and Why Use Them? 值得读,更多;
Magic Methods
- PHP reserves all function names starting with
__
as magical. - __get()
- __set()
Namespaces
- encapsulating items(封装);