Uploader

An all around general purpose file uploader for CakePHP. Packaged as a stand alone plugin with file validation, file scanning and support for a wide range of basic mime types.

The fate of class suffixes in 5.3

Tuesday, February 2nd 2010, 2:38pm
Topics: Programming
Tags: PHP, Class, 5.3, Namespace, Suffix
Comments: 3
Permalink - Tinylink

Before PHP 5.3 was released, many programmers would suffix their classnames with the package and or module that it pertains to. For example, SessionHelper, UsersController, CommentModel, so on and so forth. But with the recent upgrade to namespaces, are these types of suffixes still required?

// Current Practice
SessionHelper();
 
// Namespace Practice
\app\libs\helpers\Session();
 
// Redundant Practice
\app\libs\helpers\SessionHelper();


That's one of many dilemma's I am running into right now when dealing with past practices and theories, and applying them to newer code. Namespaces make the suffix redundant as the package is now part of the class name (unless you are aliasing the namespace). The only deal breaking reason I can think of right now as to keep suffixes; is when you are editing multiple files (or browsing a folder), as it helps identify files from each other. But on the other hand, how many times are you going to have multiple files opened name User? Maybe twice for the model and controller.

I'm mainly posting this entry to get input from everyone else and what you think the approach should be. Right now I'm going down the path of not suffixing my classes, as the similar file name is not that much of a problem or hindrance to me. If you have any convincing arguments, let me hear them (especially since this will apply to my newer scripts)!
Related Entries:

3 Comments

10 / 2 = ?
Allowed: [code] [b] [i] [u]
  • Herman Radtke
    hermanradtke.com
    Feb 6th 2010, 15:41
    1 I normally namespace my PHP 5.2 classes using the PEAR standard: App_Libs_Helpers_Session. I have rarely noticed a problem with multiple files being open, though I do use vim exclusively.
  • Lunks
    Mar 14th 2010, 23:42
    2 PHP 5.3 namespace syntax is so awful I do not intend to use it at all. It *feels* ugly.
  • Miles Johnson
    milesj.me
    Mar 15th 2010, 20:27
    3 @Lunks - While it is ugly, that is a pretty moronic thing to say seeing as how namespaces are a god send in the PHP world.

    .App.Helpers.Session
    ::App::Helpers::Session

    Aren't that great either. Back slashes make the most sense because namespaces work similar to a directory structure.