Skip to content

Instantly share code, notes, and snippets.

@ericandrewlewis
Last active February 6, 2019 21:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericandrewlewis/e958ea506403d70b6a95 to your computer and use it in GitHub Desktop.
Save ericandrewlewis/e958ea506403d70b6a95 to your computer and use it in GitHub Desktop.
PHP Cheat Sheet

PHP is a general purpose programming language with a focus on web programming.

PHP is a dynamically typed language; the type of variables is not known and type-checking occurs at run-time.

function takes_anything($anything) {
	// ...
}

takes_anything( 12345 );
takes_anything( 'strings-too' );

Variables don't require type declarations.

$a = 3;
$b = 'glerf';

Variables have either global scope or function scope when defined in a function.

$a_global_variable = 123;

function some_function() {
	$variable_local_to_function = 456;
}

All variables are passed by value, except objects which are passed by reference.

function add_one( $number ) {
	$number = $number + 1;
}
$x = 1;
a( $x );
// $x == 1;

function add_property( $object ) {
	$object->some_property = 1;
}
$y = new StdClass;
a( $y );
// $y->some_property == 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment