Variables General

Variable names must start with a ‘$’ character (to allow the php parser to work as fast as possible by instantly know it is a variable).

A variable name must start with a letter of the alphabet or and underscore ‘_’.

Variable names may only contain: ‘a’ – ‘z’, ‘A’ – ‘Z’ and ‘_’

Variable names are case sensitive.

Variable Types

PHP will always convert a variable to the type requried by the contect it is being used in.

$number = 12345 & 67890;   //$number is used as a numeric varaible
echo substr ($number, 3, 1);   //$number is used as a string

Static Variables

Use in functions to retain a value between calls.

static $LastPostTitle = "";

Note that whilst you can assign an initial value, it must not be the result of an expression (e.g. “= 2 + 4” is not allowed)

Global Variables

global $ProductCodeName;

Every line of code in your program can access a global variable.

Note that you can’t use = when declaring a global variable.  Assign the value seperately.

Integers

Integer size is platform-dependent, safest is to assume a maximum value of about two billion (32 bits signed).

64-bit platforms usually have a maximum value of about 9E18

Unsigned integers are not supported in PHP

If PHP encounters a number, or the result of an operation, that is beyond the bounds of the integer type, it will be interpreted as a float instead.

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *