Press "Enter" to skip to content

PHP5.4的新特性

PHP5.3刚出来不久, PHP6孕育中的同时, PHP5.4又放出了第一个alpha版本.
5.4主要包括以下特性:

Added: Traits language construct
Added: Array dereferencing support
Added: DTrace support
Improved: Improved Zend Engine memory usage and performance
Moved: ext/sqlite moved to pecl (sqlite3 support is still built-in)
Removed: break/continue $var syntax
Removed: register_globals, allow_call_time_pass_reference, and register_long_arrays ini options
Removed: session_is_regisitered(), session_registered(), and session_unregister()

我们重点关注下新增的这三点...

Filed in PHP应用, 随笔
with 16 Comments

Serialize/Unserialize破坏单例

我们经常采用如下方式定义单列:

class Singleton {
    private static $instance = NULL;
    /** 不容许直接调用构造函数 */
    private function __construct() {
    }
    /** 不容许深度复制 */
    private function __clone() {
    }
    public static function getInstance() {
        if (NULL === self::$instance) {
        	self::$instance = new self();
		}
        return self::$instance;
    }
}

很多人都会记得对深度copy的保护, 但, 其实我们却疏忽了一点...

Filed in PHP应用, 随笔
with 15 Comments

HTTP 204和205的应用

之前和人讨论过这个问题,,, 今天感冒在家休息, 就回忆了一下, 整理如下.
我们很多的应用在使用Ajax的时候, 大多数情况都是询问型操作, 比如提交数据, 则Ajax只是期待服务器返回:

{status: 0, message:""} //status 0代表成功, 非零的时候, message中包含出错信息.

Filed in Js/CSS, PHP应用, 随笔
with 46 Comments

Expect:100-continue

在使用curl做POST的时候, 当要POST的数据大于1024字节的时候, curl并不会直接就发起POST请求, 而是会分为俩步,

  1. 发送一个请求, 包含一个Expect:100-continue, 询问Server使用愿意接受数据
  2. 接收到Server返回的100-continue应答以后, 才把数据POST给Server
  

Filed in PHP应用, 随笔
with 20 Comments