PHP parser/execution order, classes extending classes defined later in file -
<?php class b extends { public $attribute2; function operation2() { echo 'operation2'; } } $b = new b(); $b->operation1(); $b->operation2(); class { public $attribute1; function operation1() { echo 'operation1'; } }
it shows output: operation1operation2
question:
i put class a{}
@ end of script, when goes first line class b extends a
thought show error message, undefined class a
, not, why?
the order in define classes in file not matter. php not go through script line line. parse whole file, load classes, , execute procedural code.
if remember correctly, hasn't been case. think php 3 had difficulty this.
Comments
Post a Comment