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.
with 0 CommentPeople 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.
with 0 CommentWhy 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.
with 0 CommentA 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.
with 0 CommentAfter 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.
with 0 CommentWhy 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.
with 0 CommentPHP-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.
with 0 CommentA 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.
with 0 CommentPHP 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.
with 0 CommentTaint-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.
with 0 Comment