Default values of uninitialized variables on PHP

<?php // Unset AND unreferenced (no use context) variable; outputs NULL var_dump($unset_var); // Boolean usage; outputs ‘false’ (See ternary operators for more on this syntax) echo($unset_bool ? «true\n» : «false\n»); // String usage; outputs ‘string(3) «abc»‘ $unset_str .= ‘abc’; var_dump($unset_str); // Integer usage; outputs ‘int(25)’ $unset_int += 25; // 0 + 25 => 25 var_dump($unset_int); […]

Variables in PHP

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive. Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, […]

NULL, the special value on PHP

The special NULL value represents a variable with no value. NULL is the only possible value of type NULL. Note: The null type was introduced in PHP 4. A variable is considered to be null if: it has been assigned the constant NULL. it has not been set to any value yet. it has been […]

Object Initialization on PHP

To create a new object, use the new statement to instantiate a class: <?php class foo { function do_foo() { echo «Doing foo.»; } } $bar = new foo; $bar->do_foo(); ?> Converting to object If an object is converted to an object, it is not modified. If a value of any other type is converted […]

Arrays on PHP

An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be […]

Strings on PHP

A string is series of characters, therefore, a character is the same as a byte. That is, there are exactly 256 different characters possible. This also implies that PHP has no native support of Unicode. See utf8_encode() and utf8_decode() for some basic Unicode functionality. Note: It is no problem for a string to become very […]

Floating point numbers

Floating point numbers (also known as «floats», «doubles», or «real numbers») can be specified using any of the following syntaxes: <?php $a = 1.234; $b = 1.2e3; $c = 7E-10; ?> Formally: LNUM [0-9]+ DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*) EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM}) The size of a float is platform-dependent, although a maximum of […]

Integers on PHP

An integer is a number of the set ? = {…, -2, -1, 0, 1, 2, …}. Syntax Integers can be specified in decimal (base 10), hexadecimal (base 16), or octal (base 8) notation, optionally preceded by a sign (- or +). To use octal notation, precede the number with a 0 (zero). To use […]

PHP supports eight primitive types.

Four scalar types: boolean integer float (floating-point number, aka double) string Two compound types: array object And finally two special types: resource NULL This manual also introduces some pseudo-types for readability reasons: mixed number callback And the pseudo-variable $…. Some references to the type «double» may remain in the manual. Consider double the same as […]

Booleans on PHP

This is the simplest type. A boolean expresses a truth value. It can be either TRUE or FALSE. Note: The boolean type was introduced in PHP 4. Syntax To specify a boolean literal, use the keywords TRUE or FALSE. Both are case-insensitive. <?php $foo = True; // assign the value TRUE to $foo ?> Typically, […]