Press "Enter" to skip to content

Answering a Question on bugs.php.net (Why __get Is Called Twice After unsetting a Private Property)

Why does echo $example->p1 call __get twice after unset($example->p1)? Laruence walks through zend_read_property: an unset private property isn't found in properties, so __get is invoked; inside __get, $this->$elmname is a read in the class scope where the property IS declared (named Examplep1), triggering a second, differently-named guard before the in_get recursion guard finally stops it.

Filed in English, PHP应用, PHP源码分析
with 0 Comment

Some Resources for PHP Extension Development

Laruence's starter guide for anyone picking up PHP extension work: read 'Extending and Embedding PHP', mine the PHP source's ext/ directory for real Zend_API examples, use the pecl-dev mailing list and efnet #php.pecl for questions, write phpt test cases, build PHP with --enable-debug so your extension runs clean, and check for leaks with valgrind.

Filed in English, 随笔
with 0 Comment

Optimizations in the Zend Engine (PHP 5.4)

How PHP 5.4's 'improved Zend engine performance, reduced memory' actually works: (1) class property/static/const Hashtables are now allocated lazily only when non-empty; (2) opcode operands no longer each carry a zval but point into a per-op-array literal table, shrinking an opcode from 72 to 28 bytes on 32-bit; (3) literal strings become immutable 'internal strings' with pre-computed hashes. Includes dev-team benchmarks (19–26% on micro benches).

Filed in English, PHP源码分析, 随笔
with 0 Comment

Introducing the New Type Descriptors in the Zend Parameters Parser

Since PHP 5.3, zend_parse_parameters gained new descriptors: f (callback, returns zend_fcall_info + cache), H (array or HASH_OF(object) — lets an object be accepted where an array is expected), L (clamped long), Z (raw zval**), and * / + (0-or-more / 1-or-more variadic args). Cuts down the manual validation you used to do for callbacks and objects-as-arrays.

Filed in English, PHP应用, PHP源码分析
with 0 Comment

New Features in PHP 5.4

A PHP 5.4 alpha1 feature roundup: Traits (lightweight method reuse via 'use', with fixed conflict-resolution rules), array dereferencing ($a = explode(...)[0], and even lvalue use), DTrace support, plus the new built-in Webserver SAPI (php -S localhost:8000). Also notes the removals: break/continue $var, register_globals, etc.

Filed in English, PHP应用, 随笔
with 0 Comment

PHP Performance Optimization

Laruence's four takeaways from a PHP performance talk: (1) optimization advice is about nipping problems in the bud while coding, not a rulebook to apply after a problem appears; (2) advice is a guard against abuse, not a law — e.g. batch assign() beats repeated __set magic calls; (3) advice is language-specific — an interpreted language does none of the compiler optimizations C does, and every symbol costs a Hash Lookup; (4) dig to the bottom — one high-level statement may compile to hundreds of lines of C.

Filed in English, PHP应用, 随笔
with 0 Comment