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

Tim Cotten:
How to Screw Up Singletons (in PHP)
Nov 08, 2016 @ 12:58:05

In a recent post to his site Tim Cotten talks about how it's possible to screw up singletons in PHP. Singletons are a design pattern that returns the same object once it is created each time the method is called.

“Echo chambers” are an oft-encountered downfall of developers when learning new skills or implementing unfamiliar systems. What begins as a simple question leads to a collection of up-voted knowledge perfectly ready to be copied into your project?—?a great thing for productivity (if you don’t mind getting it wrong).

[...] With that example of echo chambers in mind let’s follow the path of a developer deciding to implement the Singleton pattern in PHP.

He goes through the mindset of a PHP developer wanting to use a singleton in their application, finding an example on the web for their need (making a PDO instance). He gives a sample implementation based on the web examples and tries to execute a test script....with a less than helpful error message. He points out that he's not picking on the source of the example itself, but using it as an example of the "echo chamber" idea perpetuating an example without understanding the logic.

He continues along this same path of thinking with an example from another source - StackOverflow. He cites a specific example, points out the issue and the code it contains. He ends the post with some helpful suggestions on how to "break" this echo chamber and improve the resources in various places on the web.

tagged: singleton echochamber examples stackoverflow phptherightway bestpractices

Link: https://blog.cotten.io/how-to-screw-up-singletons-in-php-3e8c83b63189#.8n7u746sw

StackOverflow:
Developer Survey Results 2016
Mar 21, 2016 @ 09:16:15

Each year the StackOverflow site asks the developers that use its services to participate in a survey with a wide range of questions. They've just posted the results of their latest round - the 2016 edition.

This year, over fifty thousand developers shared where they work, what they build, and who they are. You are about to read the results of the most comprehensive developer survey ever conducted. We asked them 45 questions. Key highlights include the following:

For the first time, more developers are using Mac than Linux as their primary OS. Only 7% of developers identify as "rockstars". Most developers prefer dogs to cats. (But not developers in Germany.)

The results of the survey are broken up into several main sections, each with their own statistics (and graphs for some) showing the results:

  • Developer Profile (including Geography, Age, Experience and Education)
  • Technology (includes Most Loved/Dreaded/Wanted, Top Paying Tech and Development Environments)
  • Work (including Job Priorities, Salary, Teams and Remote/In-office)
  • Community (Visit Frequency, Motivation and Asking/Answering)

You can check out the details these results in the full page output.

tagged: developer survey results 2016 stackoverflow

Link: http://stackoverflow.com/research/developer-survey-2016

Drupal Motion:
PHP is not dead
Mar 27, 2013 @ 11:12:42

In this new post to his Drupal Motion site, David Corbacho shares some statistics about why PHP "isn't dead yet" and that despite the slow adoption of the latest versions of the language, it's still as popular as it ever was.

This is a follow-up on the article Dries Buytaert wrote in 2007 PHP is dead... long live PHP!. In the article he shared same concern that Nick Lewis for the slow adoption rate of PHP 5, less than 20% at that time. And he encouraged to upgrade to PHP 5. [...] Well, PHP 5 adoption rate is 96.9%, and PHP 4 is quite dead. Mission accomplished. Let's have a look to the overall PHP health.

He shares data from a few sources about the popularity and adoption of PHP in applications/sites all across the web. Sources include Netcraft survey results, W3Tech usage summaries and Stack Overflow tagging matches (complete with graphs of each set of data).

tagged: statistics popularity language netcraft w3tech stackoverflow

Link:

Christian Weiske's Blog:
How to integrate PHP_CodeSniffer with Git repositories?
May 27, 2011 @ 11:16:48

Christian Weiske has a problem he hopes you can help with - he's trying to get the PHP_Codesniffer tool integrated into his git workflow (well, the workflow of his team) as an automatic process that runs on commit. Unfortunately he's having some issues.

At work, we used a SVN server and enforced our project coding standard with a pre-commit hook on the server that ran PHP_CodeSniffer. Whenever a developer tried to commit some code that does not match the standard, he got it rejected. [...] The only way to enforce the standard is a pre-receive hook on our central Git repository server that all devs push to. Just installing the SVN hook on it isn't the solution, though.

Because of how git handles commits (possibly multiple in one push) the usual methods won't work. Other tricky things like file renaming and allowing for legacy code check-ins are also needed. He's posted the question on StackOverflow too, but no one's come up with a good answer yet (at the time of this post).

tagged: git phpcodesniffer codesniffer commit hook stackoverflow

Link:

Zend Developer Zone:
Using the Stack Exchange API with PHP (part 2)
Jan 21, 2011 @ 11:12:22

The Zend Developer Zone has posted the second part of a series from Vikram Vaswani about using the Stack Exchange API to pull questions and comments users have posted to the site. In this second part of the series he shows how to get more information about those users and their activities.

The thing to remember about questions, answers and comments, though, is that they don't exist in a vacuum. They're created by users, and it's the users that make the site tick. That's why the Stack Exchange API includes a large number of methods designed to let developers access user profiles and timelines, and unearth the relationships between users and their posts. This article will focus primarily on this dimension of the Stack Exchange API, illustrating how to search for users, obtain user profiles and timelines, and retrieve information on a user's questions, answers, comments, badges and tags.

You'll need to get the StackPHP PEAR package to follow along with the code examples (it does some of the hard work for you). He shows how to:

  • Grab a list of users ordered by reputation
  • Search for usernames matching a string
  • Get badge information (in general and for a user)
  • Finding a user's activity timeline

Near the end he also includes an example of using the Zend_Paginator component of the Zend Framework to filter down the results to a more manageable size.

tagged: stackoverflow api tutorial pear stackphp

Link: