PROGRAMMING     CLIMBING

  minte9
reminder




Last update:   18-02-2022

Type

PHP will implicitly change the type of a variable as needed (loosely typed).
 
/**
 * PHP will implicitly change the type of a variable as needed.
 * 
 * This contrasts with strongly typed languages, like C and Java.
 * In Java variables can only contain one type of data ...
 * throughout their existence. 
 */

$a = "abc";
echo gettype($a); // string

$a = 0 + "1";
echo gettype($a); // integer

$a = new ArrayObject();
echo gettype($a); // object

Naming

Variables must start with a letter or an underscore.
 
/**
 * Variables must be named using only letters, numbers and underscore.
 *      $name/ - invalid name
 * 
 * Variables must start with a letter or an underscore.
 *      $1name - invalid start
 */

$name = 'valid'; // valid name
$_name = 'valid'; // valid start

Case

Variables are are case sensitive.
 
/**
 * In PHP Variables are one of only two identifier types ...
 * that are case-sensitive. The other are constants.
 */

error_reporting(E_ALL);

$Name = "John";
echo $name; 
    // Undefined variable: name

const NAME = "Bob";
echo name;
    //Undefined constant: name

Questions     github Variables
Naming
        A B C D E F
🔔
1/3