<?php
class B extends A
{
public $attribute2;
function operation2()
{
echo 'operation2';
}
}
$b = new B();
$b->operation1();
$b->operation2();
class A
{
public $attribute1;
function operation1()
{
echo 'operation1';
}
}
It shows the output: operation1operation2
Question:
I put the class A{}
at the end of script, so when it goes to the first line class B extends A
I thought it will show an error message, something like undefined class A
, but it does not, why?
The order in which you define those classes in the file does not matter. PHP does not simply go through your script line by line. It will parse the whole file, load any classes, and execute the procedural code.
If I remember correctly, this hasn't always been the case. I think PHP 3 had difficulty with this.
Because PHP is Interpreted Languages, it will precompile some code. such as 'include' , 'require' , it will precomplie also