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

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -