
Okay, that makes sense. I’m all for making it a bit more fool-proof.naderman wrote:Easily happens that you end up doing something like this without the braces. The statement is always executed, even though the formatting makes it look like it will be conditional. That's part of what I meant about braces making it absolutely unambiguous.
naderman wrote:It has become much more common in PHP projects and it's part of the autoloading standard for PHP 5.3.
$lang = array(
'SOMETHING_FREAKY' => 'foo',
'PHPBB_ROCKS' => 'bar',
);
foreach ($ary as $key => $value)
{
$call = strtolower($key);
if (method_exists(self::$plugin, $call))
{
self::$plugin->$call;
}
} foreach ($ary as $key => $value)
{
$call = str_replace('_', '', mb_convert_case($key, MB_CASE_TITLE, 'UTF-8'));
if (method_exists(self::$plugin, $call))
{
self::$plugin->$call;
}
} function ConvertToCamelCase($string)
{
return str_replace('_', '', mb_convert_case($key, MB_CASE_TITLE, 'UTF-8'));
}
// [...]
foreach ($ary as $key => $value)
{
$call = ConvertToCamelCase($string);
if (method_exists(self::$plugin, $call))
{
self::$plugin->$call;
}
} $SomeInstanceVariable = 'foo'; $some_instance_variable = 'foo'; public function GenerateTextForDisplay(object $object, array $data)
{
return;
} public function generate_text_for_display(object $object, array $data)
{
return;
} $MovieClip = ContainerMCGroup::MovieClip(); $movie_clip = container_mc_group::movie_clip(); 
EXreaction wrote:Indeed, IfindCamelCaseHarderToRead_than_what_we_use_now.



Well, a basic example.naderman wrote:The code generation thing seems rather fabricated to me.
$string = 'foo';
$$string = 'bar';
echo $foo;
$obj_string = 'SomeClass';
$object = new $obj_string;
$method = 'getData';
$object->$method(); But not all of them are! Take a look at the SPL Functions as an example. Not "All Iterators" are CamelCase, only Class names and methods are lower camel case. Making everything CamelCase is actually not consistent with PHP's coding standards.naderman wrote:PHP's traditional functions are based on C naming conventions, new parts like the SPL are entirely camel case. And as I said I think following a PHP project interoperability standard outweighs all of this.
PHP Userland Naming Rules wrote:Function names use underscores between words, while class names use the camel case rule (there are some exceptions for older classes and functions).
PHP Coding Standards Rules wrote:5. Variable names should be in lowercase. Use underscores to separate between words.
6. Method names follow the 'studlyCaps' (also referred to as 'bumpy case' or 'camel caps') naming convention, with care taken to minimize the letter count. The initial letter of the name is lowercase, and each letter that starts a new 'word' is capitalized::
Good:
'connect()'
'getData()'
'buildSomeWidget()'
Bad:
'get_Data()'
'buildsomewidget'
'getI()'
7. Classes should be given descriptive names. Avoid using abbreviations where possible. Each word in the class name should start with a capital letter, without underscore delimiters (CampelCaps starting with a capital letter). The class name should be prefixed with the name of the 'parent set' (e.g. the name of the extension)::
Good:
'Curl'
'FooBar'
Bad:
'foobar'
'foo_bar'

'TAB_TAB'if (($some variable_with a long_name > 3 && $some variable_with a long_name < 17 && $today_is _tueseday) || $next_week_i_will_get_my_annual_bonus || $your_name == "AL")
'TAB_TAB'if (($some variable_with a long_name > 3 && $some variable_with a long_name < 17 && $today_is _tueseday) ||
'TAB_TAB_TAB'$next_week_i_will_get_my_annual_bonus || $your_name == "AL")
'TAB_TAB'if (($some variable_with a long_name > 3 && $some variable_with a long_name < 17 && $today_is _tueseday) ||
'TAB_TAB'"___"$next_week_i_will_get_my_annual_bonus || $your_name == "AL")
naderman wrote:
- Code: Select all
if ($x > 3 && $x < 7) echo $x; $x = substr(foo($x), 5);
Easily happens that you end up doing something like this without the braces. The statement is always executed, even though the formatting makes it look like it will be conditional. That's part of what I meant about braces making it absolutely unambiguous.
if (condition)
statement1;
else
statement2;
if (condition_2) {
statement3;
statement4;
} else {
statement5;
statement6;
}
if (condition)
{
statement1;
}
else
{
statement2;
}
if (condition_2)
{
statement3;
statement4;
}
else
{
statement5;
statement6;
}
Users browsing this forum: No registered users and 3 guests