Press "Enter" to skip to content

PHP's New Feature: finally

The RFC I submitted to introduce the finally keyword into PHP was committed to the trunk. A quick rundown: finally removes the need to write cleanup twice (once in catch, once after), and — a gotcha — returning inside a finally overrides the return value from the try block. The code shipped with PHP 5.5.

Filed in English, PHP应用
with 0 Comment

On Separating PHP's Compilation and Execution

People keep proposing separating PHP's compile and execution steps for performance and code protection. My take: PHP compilation is already linear and fast, separation hurts instant-edit workflow, and APC/Zend O+ already give you that benefit. A real solution exists anyway — APC's apc_bin_dumpfile/apc_bin_loadfile export opcodes to .bin files you load on the server.

Filed in English, PHP Extension, PHP应用
with 0 Comment

On Language Choice — Pick the One That's Easy to Use

Why Laruence argues you should choose a language by how easy it is to pick up rather than how sophisticated it looks. A language is a tool whose value lies in letting you solve real problems fast; the more arcane the syntax, the larger the learning cost and the longer before you can ship anything. He contrasts C with C++ (Primer, Effective C++, the STL...), notes that PHP is more like C — one book, or even just the manual, is enough — and warns of the contradiction that mastering an advanced language needs project experience while project experience needs the language first. Don't put the cart before the horse: learn something easy and start solving real problems.

Filed in English, GNU C/C++, 随笔
with 0 Comment

Please Release Your Resources Manually

A dev argued PHP releases all resources at request end so fclose/mysql_close are unnecessary. Wrong: in long-running or high-traffic contexts, holding connections until request end exhausts mysql.max_connections, file handles, and memory peak. Release resources as soon as you're done with them — if a PHP book says otherwise, burn it.

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

Some Yaf Resources

After answering the same Yaf questions over and over, a roundup of commonly used resources for learning/using Yaf: official Chinese/English docs, the community forum and QQ/Google groups, the code-generator and class-signature tools, real-world examples, and the Windows dll releases.

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

PHP's Calling Scope

Why does Foo::bar() called from inside a method still get a $this? Because in PHP, whether a call is static isn't decided by the '::' operator but by the calling scope. A '::' call made from within an instance context inherits that object's scope, which is also why parent::__construct() works the way it does.

Filed in English, PHP应用
with 0 Comment

Making PHP Serve File Downloads Faster

PHP-based file downloads (headers + readfile) let you do stats and auth checks, but the file still flows through PHP's memory/buffers and, under Nginx+fpm, adds extra network IO. The better path: set an X-Sendfile header and let Apache's mod_xsendfile (or the Nginx/Lighttpd equivalents) stream the file straight to the client, bypassing PHP entirely.

Filed in English, PHP应用
with 0 Comment

How to Contribute Code to PHP

A step-by-step walkthrough for contributing to PHP: fork php/php-src on github, clone your fork, fix the bug, commit (79-char first line, 'Fixed Bug #NNN' for bug reports), and send a pull request. New features/syntax additionally require an RFC and an email to internals@lists.php.net. Note: C89-only, no camelCase, tiny fixes go as patches to bugs.php.net.

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

PHP Demands More from the Programmer

PHP is a compiled language but its compilation does no semantic optimization — it faithfully translates your code to opcodes. So the compiler won't hoist a strlen out of a loop or cache a constant string concat. You have to think about how your code actually executes, because PHP doesn't hand the optimization work to the compiler the way other languages do.

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

Taint-0.3.0 (An XSS codes sniffer) released

Taint-0.3.0 milestone release: a PHP extension that detects XSS (tainted strings), SQL injection, and shell injection by tracking taint from $_GET/$_POST/$_COOKIE. It catches cases static analysis can't, like echo $$name, and reports the exact tainted output. Full list of taint-checking, sanitizing, and taint-preserving functions included.

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