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

Ben Ramsey:
Composer: Missing Distributions for Explicit References
Jun 18, 2015 @ 10:14:31

Ben Ramsey has shared an interesting issue he's come across when installing packages via Composer where it installed a different version than expected when he ran an install. The problem turned out to be from an unexpected place.

For applications I control that are not distributed to the public, I like to hard-lock my Composer dependencies to a specific version. [...] Sometimes a library has updates that haven’t yet been released, and I need to use these right away. Composer allows me to specify the specific commit I want to use for a library. In this way, I can hard-lock a dependency to a specific state, even when there is not yet a release for the changes I need. This has worked well until today, when I tried to do a fresh composer install. After installing, one library contained files and methods that I did not expect. It turns out Composer was grabbing the HEAD of dev-master instead of the specific commit I referenced.

After some investigation into his "composer.lock" file's contents, he found the issue: a problem with the way that BitBucket handles the distribution zip files Composer requests. In his example, the zip file was of the HEAD on the repository, not of the specific commit (GitHub doesn't have this problem). His solution was using the (slower) "--prefer-source" option to grab the correct commit contents...not an ideal solution but it does what he needs.

tagged: composer missing distribution zip file explicit reference bitbucket

Link: http://benramsey.com/blog/2015/06/composer-missing-distributions/

Nikita Popov:
Internal value representation in PHP 7 - Part 1
May 06, 2015 @ 08:12:27

Nikita Popov has a new post, the first part of a series, talking about the internal handling of variables in PHP7 and how it has changed from the current/past methods.

My last article described the improvements to the hashtable implementation that were introduced in PHP 7. This followup will take a look at the new representation of PHP values in general. Due to the amount of material to cover, the article is split in two parts: This part will describe how the zval (Zend value) implementation differs between PHP 5 and PHP 7, and also discuss the implementation of references. The second part will investigate the realization of individual types like strings or objects in more detail.

He starts with an introduction to the "zval" struct type and how it relates to the "zvalue" union. He goes on to talk about reference counting on zvals and some of the reasoning/desire to change how these are handled. Finally, he gets to the zval handling coming in PHP7 and the fundamental change in zval handling - they're no longer "individually heap-allocated and no longer store a refcount themselves". This change has several advantages and including improved refcount handling and less pointers involved in determining the actual value. He includes an example of how this new zval structure is defined in PHP7 compare to the previous version too. The remainder of the post looks at other related issues including memory management, supported types and a major change to how variable references are handled.

tagged: internal value variable representation php7 zval zvalue memory reference

Link: http://nikic.github.io/2015/05/05/Internal-value-representation-in-PHP-7-part-1.html

Giorgio Sironi:
The full list of my articles on DZone
Apr 25, 2014 @ 10:13:43

Giorgio Sironi has posted his quite impressive list of articles he's published on the DZone.com site to his blog today. They cover a wide range of topics - everything from refactoring to design patterns out to, well, lots of other random topics.

From 2010 to the end of 2013 I have written a few articles each week on DZone. Here is the full list as a reference.

Some of the posts fall into different "series" categories including "Practical PHP Patterns", "Practical PHP Refactoring", "Practical PHP Testing Patterns" and "Lean Tools". There's some great content here - and lots of it - so be sure to check out the list and see if there's anything that catches your eye!

tagged: article list dzone series reference

Link: http://www.giorgiosironi.com/2014/04/the-full-list-of-my-articles-on-dzone.html

DZone.com:
Cloning in PHP
May 17, 2013 @ 11:09:42

In this recent post over on DZone.com Giorgio Sironi takes a look at the "clone" feature of PHP - what it is, how it can be used and things to watch out for in its use.

Cloning is an operation consisting in the duplication of a data structure, usually to avoid the aliasing problem of having different code modify the same instance in inconsistent ways. In PHP, cloning can be accomplished in multiple ways - and in some cases it can be avoided altogether.

He talks some about how objects are passed around internally during the PHP execution and how you can tell if a function works with data by reference (from the manual). He then looks at the "clone" keyword and what kinds of things are duplicated from an object when it is used. He briefly touches on the "__clone" magic method for solving the "shallow clone" problem and how, possibly, serializing the object might be a better alternative for reproducing the entire object.

tagged: clone introduction object reference serialize shallow deep

Link: http://css.dzone.com/articles/cloning-php

PHPClasses.org:
6 Reasons Why PHP is a Hobbit
Feb 18, 2013 @ 13:03:26

The PHPClasses.org site has posted a humorous look at the PHP language with several reasons why PHP is a "hobbit" (a Lord of the Rings series reference):

Sometime ago a user of the Quora site asked a question if there was a language war, which languages you support and why. Another user gave a very creative response comparing programming languages with characters of the Lord of the Rings story of JRR Tolkien.

There's six reasons listed in the post:

  • PHP is Scripted C
  • PHP is not Teaming with C++ Evil
  • PHP is Not particularly Beautiful but it is Very Useful
  • PHP is Not the Fastest Language to Execute but is Agile
  • JavaScript could be a Hobbit too but Asynchronous Programming is a Hell
  • PHP Success Causes the Envy of Others

If you're interested to see the thread where the idea for this post came from, you can read it here on Quora.

tagged: language hobbit lordoftherings reference reasons

Link:

Lee Davis' Blog:
The enum conundrum
Jul 06, 2012 @ 11:56:52

In a new post to his blog Lee Davis describes the enum conundrum - what's the right solution for effectively using ENUM-type fields in your data?

So a user signs up and I want to store a status that reflects their account, or at least an identifier representing that status. Their account could be active, disabled (temporarily), pending approval or maybe deleted. Should I use an enum? I’ve heard they’re evil. Maybe having a reference table with statuses would be better? But now I have to manage a separate table just for that one snippet of data, is that overkill? Could I maybe use that status table for other entities? Or, could I instead just use an integer and reference it on the code level? What is the right solution?

He presents three of the most common situations he's seen for people using enums in the application:

  • "I used enums all over the place" (maintenance between code and DB values)
  • "use a reference table"
  • "I could use a class constant to represent the enum" (enforced in the app)

Of the three, he suggests the third as the option with the most advantages. Not only does it make it simpler to get the allowed values for the field, but you're also more flexible in the kinds of validation you can do on the values.

tagged: enum conundrum reference table constant maintenance

Link:

CodeDevelopr.com:
50 Web Developer Documentation Manuals You Need To Know About
Jun 25, 2012 @ 11:55:11

The CodeDevelopr.com site has posted a handy reference list of 50+ guides and manuals that can make looking up those key facts easier.

This is a list of over 50+ Documentation Manuals and Guides for Programmers, Web Developers, and Web Designers. I will actively update this list with more Manuals as I come across them. If you would like something added, please leave it in the comments section below. Over time it will become more refined and better organized and in return, more useful so please bookmark and share with your friends.

Linked resources include:

tagged: documentation developer manual list reference

Link:

Mayflower Blog:
Zend Framework Application.ini Cheat Sheet
Feb 06, 2012 @ 11:42:22

On the Mayflower blog today there's a new post sharing a Zend Framework application.ini "cheat sheet" with links to pages in the ZF manual explaining the details about each of the front controller options.

All this is long gone in the past since the introduction of Zend_Application and the bootstrapping resource adapters. Zend introduced a standard bootstrapping mechanism into their framework. Many of the options from different framework components can now be configured in the applications configuration file application.ini. One problem persists although: the documentation. All the parameters for components like View, Session, Database etc. are documented either with the bootstrap resource, the component itself or both.

They've posted it to github complete with sections detailing:

  • CacheManager
  • Db
  • FrontController
  • Layout
  • Navigation
  • Router
  • Translate

...and quite a few more. This is a great reference for anyone using the Zend Framework, no matter your experience level.

tagged: zendframework applicationini cheatsheet configuration reference

Link:

Ryan Gantt's Blog:
Anonymous recursion in PHP
Aug 11, 2011 @ 10:55:35

In a recent post to his blog Ryan Gantt looks at an interesting way to get around a limitation in PHP dealing with anonymous recursion and closures that throws a Fatal error when called.

Turns out that variables called as functions must be an instance of Closure, an instance of a class which implements __invoke(), or a string representing a named function in the global namespace. In the anonymous function body above, $fibonacci is none of these. It is an undeclared, free variable in the closure created by the anonymous function. At the time when it’s called, it hasn’t been bound—hence the Notice that you would have gotten if error reporting were set at a high enough threshold - and therefore can’t be called as anything, let alone as a function.

He tried using the "use" functionality PHP closures have to bring a variable/object/etc into the scope of the running function, but it still threw an error. As it turns out, the combination of "use"-ing the object and calling it by reference handles things correctly. He takes this method and applies it in two examples - one call in an array_map function and another in an array_reduce.

tagged: anonymous recursion reference invoke closure

Link:

DZone.com:
PHP Quick Reference
Apr 06, 2011 @ 08:34:05

On DZone.com today there's a new post from Chris Shiflett sharing some timeless advice from an older copy of a PHP Quick Reference (published in 2009) about performance and security.

While cleaning out my desk, I found an old copy of a PHP Quick Reference I helped make a few years ago. On the front page are a few performance and security tips that I thought I'd share. (Performance tips are from George Schlossnagle.)

Performance tips include profile early/profile often, cache when possible and don't over-optimize. The security hints include some of the usual suspects - trust nothing, filter input/escape output and use prepared statements.

tagged: quick reference advice security performance

Link: