PHP PHP.net news server web interface
From: Date: Mon Dec 16 19:30:08 2013
Subject: Re: Flexible function naming
References: 1 2 3 4 5  Groups: php.internals 
On 16/12/2013 21:27, Robert Cerny wrote:
>
> If you look at the core PHP functions (e.g. array) and some important 
> new additions like DateTime, you will see that there is mainly two 
> styles competing: Underscore and Camelcase, so in most cases it will 
> be one synonym, sometimes two, but never what you were enumerating. 

That's not inconsistency, that's a convention in its own right: class 
and object methods are in camelCase, standalone functions are 
underscore_separated. This seems to be pretty well established in the 
PHP community now, and if you pick a different convention, then you will 
be going against the tide of libraries you integrate with.

The core functions which follow neither rule include C-style 
abbreviations like "strptime" which couldn't be automatically swapped to 
either format, and complete anomalies like "nl2br". If you named those 
functions as part of a consistent style, you would probably also follow 
stronger naming conventions than Rasmus did when he named 
"htmlspecialchars".

At the end of the day, integrating 3rd party code will always expose you 
to their design decisions in all sorts of ways - whether they use 
underscores is a pretty simple thing to remember compared to how they 
structure dependencies, what patterns they expect you to use when 
integrating / extending the code, etc.

Regards,

-- 
Rowan Collins
[IMSoP]


« previous php.internals (#70688) next »

Written by Jim Winstead. no rights reserved. (source code)