Basics of PHP - (also OOP) variables, introduction to classes, class parameters, class objects, object parameters
1. Variables - some containers that contain information.
Variable types:
- whole numbers
- string
- floating point numbers
- boolean type (Boolean) - it has only two values - true or false
Example:
$i //variable i
$c //variable c
//It is forbidden to set a variable starting with a number
$1 //can't
$1ic //can't
/* It's best to name variables with a letter or an underscore, but it's better to start with a letter and you won't have any problems.*/
$var = 1 ; // variable var is assigned 1, sign ; - means completion of the operation.
$int = 1 ; // integer - an integer
$string = 'string' ; //string variables
$float = 185.658412 ; // float - floating point numbers
$bool = false ; $bool2 = true ; //Boolean - boolean data type
//to display variables or html tags in the browser window, use echo
echo $int;
echo'
'; // outputs a line break
echo $string;
echo $float;
echo $bool;
?>
2. Introduction to classes - a class can be compared to an encyclopedic article, there is a type of objects and it can be described using classes. What a class can describe: the parameters of objects (what the class physically has) and their capabilities (what it can do).
Example:
//the class can have variables, which the class has
class Car{
// class body
var $color = 'red';
var $speed = 'fast';
}
$bmw = new Car() ; //create an instance of the Car type, an object of the Car class
echo $bmw->color.'
'; // Derive the class property from the object
$bmw->speed = 'slow' ; //Change the class property speed to slow
echo $bmw->speed ; // Derive the class property from the object
?>