In PHP I have following include hierarchy:
Offer in offer.php requires once abstractoperation.php
Demand in demand.php requires once abstractoperation.php
Response in response.php requires once offer.php and demand.php
AbstractOperation in abstractoperation.php requires once response.php
I want to add function getLazyResponses to AbstractOperation to access responses from both Offer and Demand. In c++ i would solve this issue using forward declarations, but how can this be solved in PHP?
UPDATE 3:
I put echo before and after each include in order to debug what is happening.
If I use require_once offer.php in index.php, application outputs this:
offer.php: including abstractoperation.php
abstractoperation.php: including response.php
response.php: including offer.php
response.php: included offer.php
response.php: including demand.php
demand.php: including abstractoperation.php
demand.php: included abstractoperation.php
Fatal error: Class 'AbstractOperation' not found in /web/classes/dao/demand.php on line 4
If I use require_once demand.php in index.php, application outputs this:
demand.php: including abstractoperation.php
abstractoperation.php: including response.php
response.php: including offer.php
offer.php: including abstractoperation.php
offer.php: included abstractoperation.php
Fatal error: Class 'AbstractOperation' not found in /web/classes/dao/offer.php on line 4
If I remove require_once response.php and put in comment getLazyResponses (so responses cannot be traced from operation), everthing works fine.