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

Chris Hartjes' Blog:
Scope Is Not a Mouthwash
Nov 28, 2011 @ 15:50:03

Chris Hartjes has a reminder posted to his blog today in the form of this recent post that "scope is not a mouthwash" - personal experience from his recent development where he forgot about something as simple as scoping (and it caused him all sorts of headaches).

For [a chapter in my book on dependency injection] I am using Pimple, an incredibly small but effective dependency injection container. Easy to use, simple and effective documentation, just what I was looking for. I also noticed that Pimple supported the use of closures (or anonymous functions) as a way of storing a dependency. Then things got stupid.

He shares a bit of code showing how he added it to his bootstrap but was given a "cannot find class" error when he tried to use the tool. He walks through the steps he followed to track down the problem - looking closer at Pimple, investigating closures and, the ultimate problem, namespace scoping. He was missing a "" to start his namespace and closures work slightly differently:

So why does it behave differently inside closures? I am not 100% sure, but if I had to make an educated guess I would say that when trying to resolve namespaces inside a closure, the interpretor doesn’t assume that it is already inside the global namespace, that it is in a namespace of it’s own.
tagged: namespace scoping pimple dependencyinjection

Link:

International PHP Magazine:
Poll Question: Why PHP Sucks
Nov 21, 2006 @ 14:57:00

The results of the latest International PHP Magazine are in and posted today on their site. The question this time was asking developers and visitors alike what they think sucks about PHP.

Choices included "No lexical scoping", "PEAR", and "Worst Configuration System" but one climbed to the top far above the others - "No namespacing". Trailing that at a distant second were two, getting the same number of votes - "No lexical scoping" and "Can't afford a vowel" (hmm, interesting).

Up for this week is a new poll that asks those out there that have used the Symfony framework to cast their votes about what they think is the best feature the project has included. Check it out and cast your vote today...

tagged: sucks poll question namespacing lexical scoping sucks poll question namespacing lexical scoping

Link:

International PHP Magazine:
Poll Question: Why PHP Sucks
Nov 21, 2006 @ 14:57:00

The results of the latest International PHP Magazine are in and posted today on their site. The question this time was asking developers and visitors alike what they think sucks about PHP.

Choices included "No lexical scoping", "PEAR", and "Worst Configuration System" but one climbed to the top far above the others - "No namespacing". Trailing that at a distant second were two, getting the same number of votes - "No lexical scoping" and "Can't afford a vowel" (hmm, interesting).

Up for this week is a new poll that asks those out there that have used the Symfony framework to cast their votes about what they think is the best feature the project has included. Check it out and cast your vote today...

tagged: sucks poll question namespacing lexical scoping sucks poll question namespacing lexical scoping

Link:


Trending Topics: