Looking for Advanced PHP Demos


For an internal presentation at our company, we are trying to compile list of advanced a.k.a. cool things which can be done with PHP. We are calling this “Next Web Presentation” so something which can show power of PHP along with a “cool” way of doing it.

I searched around and also walked through http://www.sitepoint.com/forums/showthread.php?78687-Advanced-PHP-Resources but couldn’t find much.

Can you please list some which we can include in our presentation?


There’s some interesting stuff here: http://www.tuxradar.com/practicalphp

Design patterns and software architecture are what I would consider “advanced” for a PHP programmer, but neither of those will give you something flashy for a presentation. Even the best architected programs will still only spit back boring looking HTML. Otherwise, you could talk about some prepackaged libraries that do cool things. The Zend and Symfony frameworks have a nice set of libraries. Zend Lucence, for example, probably ranks up there on the coolness meter.

You are right. Anything I do will be just backend and HTML will still be front end. I guess I could show them some CMS systems (Drupal etc) on how we can get up a basic site up and ready and then talk about Zend framework to create large enterprise applications.

Maybe I could also show them LDAP integration for internal applications; this is just for PMs to show what we could achieve with PHP.


Maybe something in here http://tutorialzine.com/2013/02/24-cool-php-libraries-you-should-know-about/, also , search sourceforge.net and constrain it to language: PHP

Thanks. I’ll go through that list and see what I can add to presentation

From that list, I especially like Assetic. It can combine and minify CSS and JS on the fly. It can parse SASS or LESS on the fly. Along with many other possible filters.

Goutte is also a fun one. Effectively a browser in PHP, complete with cookie sessions, response caching, and the ability to crawl the responses using CSS selector syntax.

I liked snappy one. We were looking for one for our next project and this will make it easier.

Yeah, its a good list, 24 cool PHP libraries you should know about - this time I formatted the link so the full title is readable because the list deserves to be investigated.

I suppose it depends what you mean by “Cool things”. From going to intermediate to advanced, really you’re looking at design patterns, best practices and advanced OOP theory. None of which are really PHP Specific.

Rather than repeat myself, I’ll repost my thoughts on the subject from here: http://www.sitepoint.com/forums/showthread.php?964512-Better-PHP-Development&p=5304801&highlight=#post5304801

The problem with showing them Drupal is that then you might end up having to use it shudders.

Hey Tom - some good advice there.

Regarding 3) - Dependency Injection - I currently do stuff like having a setMethod for objects I want to use with other objects. I find I can do mocking in unit testing etc this way. What advantage does the Depedency Injection Container have over this method?

Cheers! :slight_smile:

Generally I would advise against ->setDependency($foo) because it indirectly breaks encapsulation. It exposes the internal state externally. If $foo is a true dependency and some/all methods will not work correctly without it then you can end up with a seemingly fully constructed object in the application which doesn’t work as documented because it’s state is incomplete.

Setters for optional collaborators such as $router->addRoute(); are useful, but these should be reserved for cases where the object will work as advertised even if the method isn’t called. Anything which is a true dependency (Required for the object to work as intended) should always be passed in to the constructor for this reason.

On the topic of containers, from a practical perspective, the first thing you’ll notice is that they remove a lot of the programming overhead. For instance:

$a = new A(new B, new C(new D, new E(new F)));

Can be abstracted to:

$a = $dic->create('A');

The second big advantage comes with maintainability. Imagine F in the example above has a dependency of G introduced. This can be configured in the container and every time an instance of F is created it can be passed its new dependency, rather than having to go through all your code locating “new F” and then working out where to get its dependency from.

I think I get you there - so basically it’s like a way of reliably setting up your dependencies - like a central repository just for dependencies, so if you need to change the way a dependency is set up you just do it once in the container, rather than scanning your code? Makes sense.

In terms of what you said about the setDependency() method then - how would you deal with this? I have occasions where I’ll have a dependency that I don’t want to test in a unit test, so I use the setDependency() method to use a stub or mock for unit testing. I take it you’d use the dependency container in both cases, or would you use some other method like reflection in the unit test or something like that?

During the test you’d pass in a mock. As you’re already familiar with them, I’m not sure I understand your question. In terms of testing, I can’t see why:

public function testMyObj() {
     $myObj = new MyObj($this->getMock('SomeDependency'));

is any different from:

public function testMyObj() {
     $myObj = new MyObj;

I wouldn’t use a dependency injection container for testing because, firstly, you don’t want to be testing the container, and secondly, tests shouldn’t ever be complex enough to warrant object graph creation or you’re testing too much at once.

I think I get you there - so basically it’s like a way of reliably setting up your dependencies - like a central repository just for dependencies, so if you need to change the way a dependency is set up you just do it once in the container, rather than scanning your code? Makes sense.

Exactly, it means you can arbitrarily add dependencies to any class in the system at any time without breaking anything. Without using the container, imagine adding a dependency to an integral part of the system, you’d have several things to worry about: 1) In how many places is that class initialised. 2) How can the code which is calling the updated constructor access the new dependency? Without a container, you need to use a factory or pass the dependency all the way down the object graph.

Think I see what you mean - you’re saying you’d use the constructor to pass in dependencies required by the class as opposed to using a setmethod that could leave the class not fully ready for action… Yeah, nevermind, I get what you’re saying now.

If you’re interested in presenting the “web services” aspect of PHP this company has some cool PHP integrations so some of their data:


Hope this helps!