Can a parent php script require two classes, each defined with the same class name.
I know by default this will cause an Error, so i have been looking into namespace. I do not want to hardcode the namespace into the class file as it would be inflexible and depend on the person writing the class, i would prefer to do the following.
// Define namespace
require_class('a.class.php');
// Define new namespace
require_class('b.class.php');
Thanks in advance
You are not allowed to define namespaces in such manner.
See Defining Namespaces:
Namespaces are declared using the namespace keyword. A file containing a namespace must declare the namespace at the top of the file before any other code - with one exception: the declare keyword.
You can define multiple namespaces in the same file but the classes within that namespace should be place in this files too.
You may consider Using namespaces: Aliasing/Importing with allowing developers to specify initial namespace for classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With