【转】PHP5.3亲测精髓特性整理
【转】PHP5.3亲测精华特性整理
1、引入 __DIR__ magic常量 定位脚本的目录
echo __DIR__."|".dirname(__FILE__);
2、允许从2个值的or/and表达式快速的获取一个非空的值
echo (1 ?: 0) ."|". ("" ?: 0)."|". var_export(array() ?: array(1), true);
3、类添加__callStatic方法,等价于 __call(),但它是为调用静态方法准备的。下面来看示例:
class xxx{ function __call($func, $args){ echo "function name:".$func; echo "</br />"; echo "args:".var_export($args, true); } static function __callStatic($func, $args){ echo "static function name:".$func; echo "</br />"; echo "static args:".var_export($args, true); } } $x = new xxx(); $x->testfunc("oo"); echo "</br />"; xxx::teststatic("xx");
4、动态的调用静态的方法
class xx{ static function test(){ echo __METHOD__; } } $c = "xx"; $m = "test"; $c::$m();
5、延迟静态绑定(静态处理从编译时延迟到执行时)
class A{ static function whoami(){ echo __CLASS__; } static function say1(){ self::whoami(); } static function say2(){ static::whoami(); } } class B extends A{ static function whoami(){ echo __CLASS__; } } class C extends A{ static function whoami(){ echo __CLASS__; } } B::say1(); C::say2();
6、MySQLInd (高速的专门为PHP设计的MySQL调用库接口)
7、INI Magic
8、扩展的 OpenSSL 函数
9、SPL(Standard PHP Library) 优化
10、时间处理进行扩展了和添加
$date = strtotime("11-05-17 00:00:00"); echo date("Y-m-d", $date)."|"; $date = date_create_from_format("y-m-d", "11-05-17"); echo $date->format("Y-m-d");
11、垃圾回收器(为复杂和长时间运行脚本的执行结束周期释放内存的清理)
gc_enable(); // 允许垃圾回收 var_dump(gc_enabled()); // true var_dump(gc_collect_cycles()); // 某个元素的清理 gc_disable(); // 禁止垃圾回收
12、NOWDOC(不对HEREDOC进行转译)
$fubar = "xxx"; $xbar = <<<ONE this is HEREDOC $fubar ONE; $abar = <<<'TWO' this is NOWDOC $fubar TWO; echo $xbar."|".$abar;
13、匿名函数体验
$ofun = create_function('$a, $b', 'return $a*$b;'); //不要忘了分号,传统方法 echo $ofun(2, 5); $nfun = function ($a, $b){ return $a*$b; };//不要忘了分号,现代方法 echo $nfun(3, 5);
14、闭包体验
$arr = array(1, 2, 3, 5, 6, 7); $res = array_filter($arr, function($v) { return $v >4; }); var_dump($res); function countnum(){ $num = 0; $testt = function() use(&$num){ ++$num; echo $num; }; return $testt; } $t = countnum(); $t(); $t();
15、命名空间
namespace xxx; //第一个namespace需要在所有输出之前 function t(){ return __NAMESPACE__; } namespace xxx; function t(){ return __NAMESPACE__; } echo \xx\t()."|"; echo \xxx\t();

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Concepts and instances of classes and methods Class (Class): used to describe a collection of objects with the same properties and methods. It defines the properties and methods common to every object in the collection. Objects are instances of classes. Method: Function defined in the class. Class construction method __init__(): The class has a special method (construction method) named init(), which is automatically called when the class is instantiated. Instance variables: In the declaration of a class, attributes are represented by variables. Such variables are called instance variables. An instance variable is a variable modified with self. Instantiation: Create an instance of a class, a specific object of the class. Inheritance: that is, a derived class (derivedclass) inherits the base class (baseclass)

Function means function. It is a reusable code block with specific functions. It is one of the basic components of a program. It can accept input parameters, perform specific operations, and return results. Its purpose is to encapsulate a reusable block of code. code to improve code reusability and maintainability.

jQuery is a classic JavaScript library that is widely used in web development. It simplifies operations such as handling events, manipulating DOM elements, and performing animations on web pages. When using jQuery, you often encounter situations where you need to replace the class name of an element. This article will introduce some practical methods and specific code examples. 1. Use the removeClass() and addClass() methods jQuery provides the removeClass() method for deletion

In today's era of rapid technological development, programming languages are springing up like mushrooms after a rain. One of the languages that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

Class is a keyword in Python, used to define a class. The method of defining a class: add a space after class and then add the class name; class name rules: capitalize the first letter. If there are multiple words, use camel case naming, such as [class Dog()].

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

When writing PHP code, using classes is a very common practice. By using classes, we can encapsulate related functions and data in a single unit, making the code clearer, easier to read, and easier to maintain. This article will introduce the usage of PHPClass in detail and provide specific code examples to help readers better understand how to apply classes to optimize code in actual projects. 1. Create and use classes In PHP, you can use the keyword class to define a class and define properties and methods in the class.

Background Recently, key business codes have been encrypted for the company framework to prevent the engineering code from being easily restored through decompilation tools such as jd-gui. The configuration and use of the related obfuscation scheme are relatively complex and there are many problems for the springboot project, so the class files are encrypted and then passed The custom classloder is decrypted and loaded. This solution is not absolutely safe. It only increases the difficulty of decompilation. It prevents gentlemen but not villains. The overall encryption protection flow chart is shown in the figure below. Maven plug-in encryption uses custom maven plug-in to compile. The class file specified is encrypted, and the encrypted class file is copied to the specified path. Here, it is saved to resource/corecla.
