Skip to content

Instantly share code, notes, and snippets.

@phpguru
Last active December 23, 2022 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpguru/2f6f40ac5e0ff6dd4816fc9bacf539af to your computer and use it in GitHub Desktop.
Save phpguru/2f6f40ac5e0ff6dd4816fc9bacf539af to your computer and use it in GitHub Desktop.
PHP Old-school formatting in 10-year-old legacy project
<?php
if ($a = 1)
{
$code = 'here';
function('call','there');
alignment('true');
}
else if ($b = 2)
{
$code = 'there';
$obj->some_method('call','different');
alignment('true');
}
else
{
$longLineExample = "Lorem ipsum "
." dolor sit amet ". string_function('here')
." consequitor spicing";
$code = 'here';
function('call','there');
alignment('true');
}
$name = 'example_';
for ($x = 1; $x <= 10; $x++)
{
$name .= $x;
if (strlen($name > 20)
{
$name = modify($name);
$pass = $security->secret($name);
}
else
{
$name = strtoupper($name);
$x = substr($name, 3, 12);
}
do_the_thing();
finish_this_loop();
$x .= $x . $name
}
other_code_follows();
@phpguru
Copy link
Author

phpguru commented Dec 23, 2022

Best described as:

if elseif, else, do, while, for statement formatting:

  • curly brace appears on next line and indented four spaces, to align with code in that section/stanza

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment