I have 5 scripts:
database.php
parent.php
child1.php
child2.php
Another option to include_once or require_once is to use class autoloading. http://php.net/manual/en/language.oop5.autoload.php
You should use require_once and include_once. Inside parent.php use
include_once 'database.php';
And inside child1.php and child2.php use
include_once 'parent.php';
Class Parent cannot be declared because it is PHP reserved keyword so in effect it's already in use
try to use use include_once
or require_once
instead of include
or require
you want to use include_once() or require_once(). The other option would be to create an additional file with all your class includes in the correct order so they don't need to call includes themselves:
"classes.php"
include 'database.php';
include 'parent.php';
include 'child1.php';
include 'child2.php';
Then you just need:
require_once('classes.php');
I had this problem before and to fix this, Just make sure :
My problem (before) :
I had class : Core, Router, Permissions and Render
Core include's the Router class, Router then calls Permissions class, then Router __destruct calls the Render class and the error "Cannot declare class because the name is already in use" appeared.
Solution :
I added __destruct on Permission class and the __destruct was empty and it's fixed...