PHP 5.4's Zend Engine adds the callable type hint so a function can require a callable argument without manual validation — foo(callable $callback). Works with strings, closures, and [class, method] arrays; otherwise throws a catchable fatal. For extension dev, zend_parse_parameters gains the 'f' flag.
with 0 CommentBefore PHP 5.4, upload progress required APC or the uploadprogress PECL extension — both needing extra installs and using local storage (shared memory / file system), which breaks across multiple front-ends. Arnaud Le Blanc's RFC moves progress into $_SESSION via new session.upload_progress.* settings, native and multi-machine friendly.
with 0 CommentPHP 5.4 adds array dereferencing (Felipe's change): you can now directly index into a returned array — $mid = foo()[1] — instead of the old list(, $mid, ) = foo(); or a temp variable. It also works with references, e.g. getTable()["foo"] = "laruence" when the function returns by reference.
with 0 Commentjson_encode on an object only encodes its public properties, which isn't enough for real objects. PHP 5.4 adds the JsonSerializable interface: implement jsonSerialize() to control exactly what gets encoded — compute from private members, or return a scalar in place of the object.
with 0 Commentmysqlnd_ms, a mysqlnd plugin (from the MySQL team: Andrey, Ulf Wendel, johannes), does read-write splitting and load balancing by inspecting queries — reads go to slaves, writes to the master. Configure master/slave in the plugin's ini (JSON from 1.1.0) and connect via a section name like mysqli("myapp", ...). Requires mysqlnd, the default driver since PHP 5.4 beta1.
with 0 CommentCan a regex match balanced brackets? Perl 5.6+ introduced recursive patterns: the (?R) symbol refers to the pattern itself, so #\((?R)*\)# matches arbitrarily nested balanced parens — but you must always give the recursion a terminating condition (e.g. (?R)* not (?R), else it tries to match infinitely). Also supports numbered references like (?3).
with 0 CommentAfter getting Zend maintainer rights, Laruence improved the 'Declaration must be compatible' fatal error so it now prints the expected signature — e.g. ArrayAccess::offsetSet($offset, $value) — instead of leaving you to look up the manual. Works for both interface and abstract-class methods. SVN r317206.
with 0 CommentWhy 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 Example p1 ), triggering a second, differently-named guard before the in_get recursion guard finally stops it.
with 0 CommentLaruence'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.
with 0 CommentHow 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).
with 0 Comment