Merge branch 'gh-pages' of github.com:codeguy/php-the-right-way into gh-pages

This commit is contained in:
Phil Sturgeon
2014-06-10 14:41:52 +01:00
5 changed files with 9 additions and 4 deletions

View File

@@ -23,7 +23,7 @@ PHP supports first-class function, meaning that a function can be assigned to a
functions can be referenced by a variable and invoked dynamically. Functions can be passed as arguments to other
functions (feature called Higher-order functions) and function can return other functions.
Recursion, a feature that allows a function to call itself is supported by the language, but most of the PHP code focus
Recursion, a feature that allows a function to call itself, is supported by the language, but most of the PHP code focus
on iteration.
New anonymous functions (with support for closures) are present since PHP 5.3 (2009).

View File

@@ -38,7 +38,7 @@ $statement = $pdo->query("SELECT some\_field FROM some\_table");
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo htmlentities($row['some_field']);
// PDO + MySQL
// PDO + SQLite
$pdo = new PDO('sqlite:/path/db/foo.sqlite');
$statement = $pdo->query("SELECT some\_field FROM some\_table");
$row = $statement->fetch(PDO::FETCH_ASSOC);

View File

@@ -72,7 +72,7 @@ This will output `$foo['bar']` if it exists, but will simply return a null and p
This might seem like a good idea, but there are a few undesirable tradeoffs. PHP handles expressions using an `@` in a less performant way than expressions without an `@`. Premature optimization may be the root of all programming arguments, but if performance is particularly important for your application/library it's important to understand the error control operator's performance implications.
Secondly, the error control operator **completely** swallows the error. The error is not displayed, and the error is not send to the error log. Also, stock/production PHP systems have no way to turn off the error control operator. While you may be correct that the error you're seeing is harmless, a different, less harmless error will be just as silent.
Secondly, the error control operator **completely** swallows the error. The error is not displayed, and the error is not sent to the error log. Also, stock/production PHP systems have no way to turn off the error control operator. While you may be correct that the error you're seeing is harmless, a different, less harmless error will be just as silent.
If there's a way to avoid the error suppression operator, you should consider it. For example, our code above could be rewritten like this

View File

@@ -22,3 +22,8 @@ available as a book completely for free
* [Modernizing Legacy Applications In PHP](https://leanpub.com/mlaphp) - Get
your code under control in a series of small, specific steps
* [Building Secure PHP Apps](https://leanpub.com/buildingsecurephpapps) - Learn the security basics that a senior developer usually acquires over years of experience, all condensed down into one quick and easy handbook
* [The Grumpy Programmer's Guide To Building Testable PHP Applications](https://leanpub.com/grumpy-testing) - Learning to write testable doesn't have to suck
* [Securing PHP: Core Concepts](https://leanpub.com/securingphp-coreconcepts) - A guide to some of the most common security terms and provides some examples of them in every day PHP
* [Scaling PHP](https://leanpub.com/scalingphp) - Stop playing sysadmin and get back to coding
* [Signaling PHP](https://leanpub.com/signalingphp) - PCNLT signals are a great help when writing PHP scripts that run from the command line.

View File

@@ -6,7 +6,7 @@ description: "An easy-to-read, quick reference for PHP best practices, accepted
{% capture welcome_content %}{% include welcome.md %}{% endcapture %}
{{ welcome_content|markdownify }}
{% capture backtotop %}[Back to Top](#top){.top}{% endcapture %}
{% capture backtotop %}[Back to Top](#top){:.top}{% endcapture %}
{% for post in site.posts reversed %}
{% if post.isChild != true and loop.first != true %}
{{ backtotop|markdownify }}