PHP Directory


  • Git and WordPress: How to Auto-Update Posts with Pull Requests

  • Interview with Colin O’Dell

    The post Interview with Colin O’Dell appeared first on Voices of the ElePHPant.

  • Displaying errors in Expressive with Twig

    If you're not using the Whoops error handler with Expressive and are using the Twig renderer, then you are given no information about the problem that occurred, even in debug mode.

    To fix this, I changed error.html.twig to this:

    {% extends '@layout/default.html.twig' %}
    {% block title %}{{ status }} {{ reason }}{% endblock %}
    {% block content %}
        <h2>This is awkward.</h2>
        <p>We encountered a {{ status }} {{ reason }} error.</p>
        {% if status == 404 %}
                You are looking for something that doesn't exist or may have moved. Check out one of the links on this page
                or head back to <a href="{{ path('home') }}">Home</a>.
        {% endif %}
        {% if error %}
            <h2>Error details</h2>
            <p>Message: <strong>{{ error.getMessage() }}</strong></p>
            <p>in <tt>{{ error.getFile() }}:{{ error.getLine() }}</tt></p>
            <pre>{{ error.getTraceAsString() }}</pre>
            {% set prev = error.getPrevious() %}
            {% for i in 1..10000 if prev %}
                <h3>Previous error</h3>
                <p>Message: <strong>{{ prev.getMessage() }}</strong></p>
                <p>in <tt>{{ prev.getFile() }}:{{ prev.getLine() }}</tt></p>
                <pre>{{ prev.getTraceAsString() }}</pre>
                {% set prev = prev.getPrevious() %}
            {% endfor %}
        {% endif %}
    {% endblock %}

    The new part is the within the {% if error %} block. In debug mode, error is set to the exception that was thown and is blank otherwise, so you won't leak sensitive information (as long as you don't enable debug in production).

    Inside the {% if error %} block, I render the error message and where it happened and then iterate down through any previous errors and displays their information too. Interestingly, there isn't a while loop in Twig which would be ideal to recursively iterate through the previous errors. To solve this, I used the construct which works nicely as long as I don't have more than 10,000 previous errors!

    If you use the Zend-View or Plates rendering engines, I imagine similar code would work there too.

  • Choose Dependency Injection — If You Can

    Some people say, “You don’t need to use dependency injection for everything. Sometimes dependency injection is not the best choice.”

    It occurs to me that the people who say this are the ones who can’t use it for everything. They say “choose what’s best for your situation”, but their situation precludes the use of dependency injection in the first place.

    Anyone who says “X is not always the best choice”, but does not have X as an available option, is being disingenuous. They are not choosing against X based on an examination of the tradeoffs involved. Instead, they are making a virtue out of necessity, then posing as virtuous for not having better choices available.

    Dependency injection is, by default and until proven otherwise, the best choice — when you have that choice available to you.

    If that choice is not available to you, if you cannot construct an object using any form of dependency injection (constructor injection, setter injection, etc.), then you need to consider if the code in question has been designed poorly.

  • Atlas.Orm 2.0 Is Now Stable

    I am very happy to announce that Atlas, a data-mapper for your persistence layer in PHP, is now stable for production use! There are no changes, other than documentation updates, since the beta release two weeks ago.

    You can get Atlas from Packagist via Composer by adding …

        "require": {
            "atlas/orm": "~2.0"

    … to your composer.json file.

    The updated documentation site is at (with both 1.x and 2.x documentation).

    Submit issues and pull requests as you see fit!

  • Interview with Adam Culp

    The post Interview with Adam Culp appeared first on Voices of the ElePHPant.

  • Symfony Flex: Paving the Path to a Faster, Better Symfony

  • Interview with Ann Gaffigan

    The post Interview with Ann Gaffigan appeared first on Voices of the ElePHPant.

  • PHP 7.2.0 Release Candidate 4 Released

    The PHP development team announces the immediate availability of PHP 7.2.0 RC4. This release is the fourth Release Candidate for 7.2.0. All users of PHP are encouraged to test this version carefully, and report any bugs and incompatibilities in the bug tracking system. THIS IS A DEVELOPMENT PREVIEW - DO NOT USE IT IN PRODUCTION! For more information on the new features and other changes, you can read the NEWS file, or the UPGRADING file for a complete list of upgrading notes. These files can also be found in the release archive. For source downloads of PHP 7.2.0 Release Candidate 4 please visit the download page, Windows sources and binaries can be found at The next Relase Candidate will be announced on the 26th of October. You can also read the full list of planned releases on our wiki. Thank you for helping us make PHP better.
  • Your unit test methods need docblocks too

:: Our Favorites

Featured Sites Using PHP

>Atlanta Real Estate