Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen:
Replacing Pimple in a Slim 3 application
Jul 14, 2015 @ 10:56:00

Rob Allen has a quick post to his site showing you how to replace the default Slim dependency injection container (Pimple) with another option.

One feature of Slim 3 is that the DI container is loosely coupled to the core framework. This is done in two ways: The App composes the container instance rather than extending from it and internally, App depends on the container implementing the container-interop interface. [...] Slim 3 ships with Pimple by default, but my preference is for ZendServiceManager, so I decided to integrate ServiceManager into Slim 3.

While he's packaged it up into an installable library, he also walks through the process. He shows how it was implemented via a callback resolver in the ServiceManager. He had a little issue with the "set" functionality but solved it with a few simple "if" checks on the content type before setting it to the container.

tagged: replace pimple application slim3 servicemanager zend tutorial zsmslimcontainer

Link: http://akrabat.com/replacing-pimple-in-a-slim-3-application/

PHPClasses.org:
Lately in PHP Podcast #46 - "Is the Hack Language Going to Replace PHP?"
Apr 21, 2014 @ 09:12:14

In the latest episode (#46) of the "Lately in PHP" podcast series Manuel Lemos and Arturs Sosins wonder if Hack will ever replace PHP.

The release of the Facebook Hack language has shaken the PHP community since it implements several frequently requested features that were never implemented, many users are considering to drop PHP in favor of Hack. This was one of the main topics discussed by Manuel Lemos and Arturs Sosins on the episode 46 of the Lately in PHP podcast. They also talked about the OpenSSL Heartbleed security bug may affect PHP sites or not, ideas for the PHP 6 engine, the need for an official PHP specification, and an advanced email validation that can provide suggestions for address typos like Google did you mean feature.

You can catch this latest episode either through the in-page audio player, by downloading the mp3 or by watching the video of the live Google Hangout recording.

tagged: phpclasses latelyinphp ep46 hack replace openssl heartbleed podcast

Link: http://www.phpclasses.org/blog/post/232-Is-the-Hack-Language-Going-to-Replace-PHP--Lately-in-PHP-podcast-episode-46.html

Nils Adermann:
Composer: Replace, Conflict & Forks Explained
Feb 19, 2014 @ 12:56:41

Nils Adermann has a new post looking at a problem with Composer where it will install a fork of a project rather than the actual project repository. He points out that it is not a security vulnerability in Composer itself, and is usually cause by using the configuration incorrectly.

Recently there has been an increase of cases in which Composer installs a fork of a package instead of the package the user expects. Most frequently these are forks of packages using a “replace” statement in their composer.json. These forks are usually meant for private use only but are still published on Packagist.

The issue stems from the use of "replace" and the publishing of those forked repositories in the Packagist service. "Replace" is meant to define a fork that is still compatible with the original project. The way that Composer handles finding the correct package to install can cause a conflict and the wrong package could end up "winning".

tagged: composer replace fork repository dependency install

Link: http://blog.naderman.de/2014/02/17/replace-conflict-forks-explained

Mike Purcell's Blog:
PHPUnit - Upgrade - Convert assertType to assertInternalType
May 21, 2012 @ 09:56:59

In this quick post to his blog, Mike Purcell mentions the deprecation of the "assertType" assertion and includes some code you can add to correct the issue in your tests.

We recently upgraded phpunit from a very old version to the current 3.6.x version (at time of writing). During the upgrade I noticed that assertType is no longer supported in many of our tests which were testing if something was a string, an array, or an object. So I had to write a quick script to update assertType to assertInternalType and figured I would post it for others if they needed to do the same.

The code goes into each of your tests (recursively) and finds the places where the "assertType" assertion is used and replaces it with its newer cousin "assertIntrnalType".

tagged: phpunit unittest asserttype assertinternaltype string replace

Link:

PHPMaster.com:
Practicing Regular Expressions with Search and Replace
Nov 23, 2011 @ 14:27:59

On PHPMaster.com today there's a new tutorial that shares a few regular expression tips about doing some search and replace in your content.

So how can you practice using regex if you are limited to just using them in your code? The answer is to use a utility, of which there are many, that uses regex for performing search and replace. I’m sure everyone is familiar with the standard “find x and replace it with y” type of search and replace. Most IDEs and text editors have built in regex engines to handle search and replace. In this article I’d like to walk through a series of exercises to help you practice using regex.

His examples are based on Netbeans but can be used in just about any IDE that supports regex (or even just your code). He shows how to match word boundaries, do some grouping, work with back references and doing some search/replace based on multiple groupings.

tagged: regular expression practice search replace boundaries group backreference

Link:

PHPBuilder.com:
PHP Simple HTML DOM Parser: Editing HTML Elements in PHP
Sep 08, 2011 @ 10:06:07

On PHPBuilder.com today there's a new tutorial from Vojislav Janjic about using a simple DOM parser in PHP to edit the markup even if it's not correctly W3C-formatted - the Simple HTML DOM Parser

Simple HTML DOM parser is a PHP 5+ class which helps you manipulate HTML elements. The class is not limited to valid HTML; it can also work with HTML code that did not pass W3C validation. Document objects can be found using selectors, similar to those in jQuery. You can find elements by ids, classes, tags, and much more. DOM elements can also be added, deleted or altered.

They help you get started using the parser, passing in the HTML content to be handled (either directly via a string or loading a file) and locating elements in the document either by ID, class or tag. Selectors similar to those in CSS are available. Finally, they show how to find an object and update its contents, either by adding more HTML inside or by appending a new object after it.

tagged: simple html dom parse tutorial selector find replace edit

Link:

JSClasses.org Blog:
Lately in JavaScript podcast - Episode 5 (Javascript to Replace PHP?)
Jun 09, 2011 @ 09:26:14

From the JSClasses.org site today there's a new episode of their "Lately in Javascript" podcast that asks the question "Is Javascript going to replace PHP?"

So it seems that recently Douglas Crockford of Yahoo commented they are considering to replace PHP with Node.js based JavaScript for server side Web applications. On episode 7 of the Lately in JavaScript podcast, Manuel Lemos and Michael Kimsal have Zachary Kessin, author of the Programming HTML 5 Applications book, to debate whether it makes sense to drop PHP for JavaScript on the server side.

You can listen to this latest episode either by using the in-page player or you can download the mp3 directly.

tagged: latelyinjavascript podcast replace javascript opinion

Link:

Bence Eros' Blog:
Life without static in PHP
Dec 20, 2010 @ 13:17:03

In this new post to his blog Bence Eros shares some of the frustrations and issues he's had when dealing with static methods and properties in his applications and how, with a bit of re-engineering, you might be able to have "life without static".

The problem with static members in PHP is the poor initialisation capabilities. The initial value of a static property can only be a literal or a named constant. [...] The same problem exists for non-static properties too, but the constructor is a dedicated place to initialize non-static properties. But since we don't have Java-like static constructors in PHP there is no place to do static property initialization. In a lot of cases people do it by putting the assignment statements after the body of the class, but this method is very ugly.

An alternate method he suggests is using a singleton to initialize and grab the value of a class value. He gives some sample code to show how it might be done, but warns that it might not be the right way to do things. It has "significant disadvantages" that could cause trouble down the road (for one, singletons make it difficult to unit test).

tagged: static class tutorial singleton replace

Link:

Seldo.com:
PHP needs to die. What will replace it?
Oct 06, 2010 @ 12:19:40

In this recent post Laurie Voss has voiced his opinion about the PHP language - that it needs to die, but also asks what should replace it.

The reason I know PHP has to die is because I've seen this before. Roughly a decade ago, PHP killed Perl. [...] As a language for newcomers, and especially for web developers, it was already dying in 1999 and was mostly dead by sometime around 2005. [...] There was no reason you couldn't write a perfect web app in Perl, but in PHP you'd do it faster and easier, despite the flaws in PHP itself which were, even then, already obvious.

He talks about moving on from PHP, why almost requiring a framework to do anything these days is a bad thing and how, despite the flaws the language has, he feels "trapped in a language that's losing its suitability for the task." He suggests that one successor might be Ruby on Rails but also points out some of the flaws it has including performance, Active Record and possible issues with code generation. He notes, though, that this isn't quite the replacement he had in mind and that there's just not something there to fill that gap.

Be sure to read the comments for lots of great opinions from both sides of the PHP opinion fence.

tagged: opinion replace language rubyonrails

Link:

Andrey Hristov's Blog:
Replacing mysqli's Connection, Result and Statement classes
Jul 09, 2010 @ 10:31:03

On his blog today Andrey Hristov has a quick post that talks about two methods to extend the functionality that the mysqli extension offers in PHP with your own custom code.

Have you ever though about extending mysqli's classes. It's pretty simple to subclass the connection class mysqli. However, subclassing mysqli_result and mysqli_stmt is not so obvious, actually I though that it's even not possible. However, never say never! After discussing mysqli's OO interface for an hour yesterday [...] I found out how one can plug his own classes.

Two code examples are provided - one for extending the mysqli_result and the other extending the mysql_stmt class. You can find more about these and other classes the mysqli extension has to offer in this section of the PHP manual.

tagged: replace mysqli connection result statement class extend

Link: