PHP 5.4 vs 5.3: Autoloading multiple classes in the same file -


firstly, bit of long one, thank reading.

my issue similar one: class not found in same file

i have custom-built framework written in 2008 php 5 , it's been upgraded on years work php 5.3. i've been looking @ 5.4 compatibility , have hit serious issue.

the orm layer automatically generates classes each db table. these classes sit in 1 file per table , our autoloader loads file when required. example, 'customer' table in 'public' schema (postgresql) have following classes: publiccustomer, publiccustomerdbreader, publiccustomerdbwriter. may not ideal set up, have.

in php 5.3, if publiccustomer required, file included, parsed , of above classes become available. if, example, static method called on publiccustomer, , method calls in publiccustomerdbreader, work fine, since class in same file.

in php 5.4, looks optimisations have been done in core. in above scenario:

  1. a static method gets called in publiccustomer.

  2. the autoloader finds , loads correct file.

  3. the php parser parses needs; publiccustomer class. has not parsed or instantiated publiccustomerdbreader class. can confirm testing if class exists , seeing if parser reaches end of file when gets included, when method called (it doesn't).

  4. the method in publiccustomer tries call method in publiccustomerdbreader. fails, since our autoloader has required file once.

it seems me have 2 solutions:

  1. separate these classes out there 1 file each (this produce huge number of files)
  2. redesign orm layer multiple classes not required.

have understood issue above properly?

does know if optimisation or change made in php 5.4 cause behaviour?

are there other potential solutions problem have not considered?

place reader/writer classes @ head of file. might consider filing bug report, since parser should halt on errors.


Comments