Possible Duplicate:
Does the order of class definition matter in PHP?
class a {
function __construct () {
$obj = new b();
echo $obj->sum();
}
}
class b {
function sum () {
return 3+4;
}
}
$obj_a = new a();
this code works, but I interest how much justified is this code? that is: first time is writed class a, in him we call class b, but class b is writed after a. in this example, wille be better way writed class b before a? or not sense?
No, the order in which the two classes are defined in the source file doesn’t matter. As long as both are defined in the same file you move them around at will.
If the classes are not defined in the same file then things can get a little more complicated, but not in a way that will impact this kind of code.