News Feed
Sections




News Archive
feed this:

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

Rob Allen:
Use statements
March 17, 2014 @ 10:13:08

Rob Allen's latest post focuses in on something that's been a part of PHP for a while now, back when namespacing was introduced - the "use" keyword. He shares some thoughts, both from others and himself, about whether or not they make code more readable.

I was having a discussion on IRC about use statements and whether they improved code readability or not. [...] Those longer class names make it a little hard to quickly parse what it going on. The [example with "use" statements] is clearly less cluttered, but is at the expense of ambiguity. Exactly what class is User? I would have to go to the top of the file to find out. Should I use aliases? If so, how should I name them?

He went out to Twitter for advice from other PHP developers on the issue too. The feedback from his question came mostly in support of the "use" statements:

  • "I think use statements just abstract where the class is coming from. Some people find that useful."
  • "I think it's helpful seeing all of the packages used by a class without having to look through the full code."
  • "One reason I like them is that I can glance at a file and know dependencies immediately."
  • "I do appreciate what you are saying about the indirection use statements introduce."

There's also a bit of talk about "aliasing" with namespaces rather than the full classname, then using the namespace and class name in the code to "minimise ambiguity".

0 comments voice your opinion now!
use statement namespace twitter advice feedback alias

Link: http://akrabat.com/php/use-statements/

Lorna Mitchell's Blog:
3 Ways to Access a Namespaced PHP Class
November 29, 2010 @ 12:49:36

Lorna Mitchell has posted three different ways you can use to get access to a namespaced class in a PHP 5.3 application, all useful depending on where you are in the application and your needs.

After what felt like years of debate over the notation to use for PHP's namespaces, it seems like the feature itself has had relatively little use or attention since it was actually implemented in PHP 5.3. We're all used to working without it but using it does make code neater.

Her three options are:

  • Refer Namespace and Class Name
  • Import the Namespace
  • Alias the Namespace and/or Class

You can find out more about namespaces in PHP applications on the PHP manual.

0 comments voice your opinion now!
namespace access method example import alias class


SitePoint PHP Blog:
How to Use PHP Namespaces (Parts 2 &3)
July 15, 2009 @ 08:16:24

The SitePoint PHP blog has posted the next two parts of their series looking at using namespaces in PHP - parts 2 and 3:

In the second part of the series they build on the basics and look at importing namespaces into a script, aliasing them to a shorter, easier to use name and some rules to consider about name resolution.

The third part of the series (the last part) looks at the keywords the namespace functionality uses and how to autoload namespaced classes to keep their namespacing intact.

0 comments voice your opinion now!
autoload keyword alias import tutorial namespace


Till Klampaeckel's Blog:
How to setup multiple stores on different domains with Magento
April 29, 2009 @ 12:05:11

On Till Klampaeckel's blog this recent post shows you how to (quick and easy) set up multiple Magento stores on different domains with the same codebase.

Multiple stores is probably the killer feature of the Magento Commerce store. It enables the needy to manage multiple stores through a single interface. Your very own mall in a box. It's also a management/deployment nightmaredream come true. A single piece of software powering multiple websites.

He sets up his directory structure and shows how to alias certain directories to ones in the local document root so that the application will find things correctly. Drop in a custom index.php "bootstrap" file to run the application and you should be all set.

0 comments voice your opinion now!
multiple store magento domain docroot alias bootstrap


Ben Ramsey's Blog:
Lampooning Benchmarks
September 27, 2007 @ 13:42:00

In response to this previous post, Ben Ramsey has relayed some of this thoughts on the benchmarks that were done by Jonathan Street comparing functions and their aliases:

Mmy first reaction was something like: "Egads! These benchmarks are stupid and misleading! These functions are simply aliases of each other. There should be no discernible difference, and any buffoon should realize this fallacy!" This was before I clicked through from PHPDeveloper.org to read his post.

After reading his data and going on to the Better Benchmarks post that followed it, he found that most of the results of additional testing came out negligible and that there was almost no difference between the two.

Ben illustrates the proof of this with a few lines pasted from the "ext/standard/basic_functions.c" in PHP's source showing that the code is shared via a PHP_FALIAS function call.

0 comments voice your opinion now!
benchmark misleading testing alias source benchmark misleading testing alias source



Community Events





Don't see your event here?
Let us know!


composer framework laravel voicesoftheelephpant interview update community package mvc language version podcast opinion release security library series symfony introduction tool

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework