Arnaud's PHP 5.4 patch stops the ternary operator from copying its second/third operand every time — a big win when the operand is a large array. PHP already uses copy-on-write for normal assignment, but the ternary bypassed it; after the patch, array-copying overhead is eliminated.
with 0 CommentPHP 5.4's new zend signal mechanism (per Rasmus's RFC) lets signal masking work in any SAPI and improves performance. Built on Yahoo's deferred-signal idea, it registers handlers for SIGALRM/SIGINT etc. at startup and defers them via a depth counter (zend_signal_globals_t.depth) instead of repeated sigaction calls, plus a new zend_signal registration interface.
with 0 Commentjson_encode always mangles Chinese into unreadable \uXXXX escapes (and inflates the payload). PHP 5.4 adds the JSON_UNESCAPED_UNICODE flag so Chinese is emitted as-is. Also mentions the other new flags: JSON_BIGINT_AS_STRING, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES.
with 0 CommentPHP 5.4 lets you write binary literals directly in code (0b1101), handy for flag bits — previously you had to go through bin2dec with a string. Also new: hex2bin() converts a hex string straight into a binary data stream, replacing the old pack("H*") workaround.
with 0 CommentPHP 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 Comment