Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
musician9426y@mojo2012 same for me unless its just a return. Then I actually prefer the 1 line in terms of readability.
-
@C0D4 well... erm... yeah... a joke... haha!
serious. i know it is likely bad practice. but i am lazy and no one ever sees my code. i'd not recommend it to a learner though. -
C0D4681386y@erroronline1 it’s ok, just tell me you don’t use alt syntax as well ( something I thought died in PHP4 ) and I’ll forgive you when you start unraveling your ternary operators.
http://php.net/manual/en/... -
@C0D4 wow! i wasn't aware of this. although i am a slow learner i see this wouldn't end well...
-
Tobyvw6986y3rd.
Also @C0D4, I use alt syntax when I place clear html between them, else I use that 3rd notation. -
i loved first, but i have a pipeline with phpcs PSR2 standard test that made me use third...
and honesly i didnt see anyone use second :) -
C0D4681386y@Codex404
They lead to unclear operations very quickly, especially when people start nesting them and having multi logic paths and variable assignments occurring, and multiple outputs. This shit can’t be tested nor can it be easily followed to work out the actual expected behaviour.
For single liners and the quick bool occurring I can live with them, but I’ve seen things I can’t bleach from my eyes.
What’s your preference for a simple if without shorthand:
if ($variable == ‘test’) echo ‘’hello’;
if ($variable == ‘test’) { echo ‘’hello’; }
if ($variable == ‘test’) {
echo ‘’hello’;
}
question
php stlyeguide if syntax