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;