I am using namespaces to resolve class name conflicts in two of the SDKs I am using in my project
I have declared a name space in one of the file like
namespace temp;
class abc extends stdClass
{
// my class def
}
when i am hitting this code i get error says temp/stdClass not found, so I need to use all default php structures, interfaces like iterators etc. so how can I import the default namespace of php or do any another setting I am missing?
A namespace is a hierarchically labeled code block holding a regular PHP code. A namespace can contain valid PHP code. Namespace affects following types of code: classes (including abstracts and traits), interfaces, functions, and constants. Namespaces are declared using the namespace keyword.
To address this problem, namespaces were introduced in PHP as of PHP 5.3. The best way to understand namespaces is by analogy to the directory structure concept in a filesystem. The directory which is used to group related files serves the purpose of a namespace.
In the PHP world, namespaces are designed to solve two problems that authors of libraries and applications encounter when creating re-usable code elements such as classes or functions: Name collisions between code you create, and internal PHP classes/functions/constants or third-party classes/functions/constants.
Multiple namespaces may also be declared in the same file. There are two allowed syntaxes. This syntax is not recommended for combining namespaces into a single file. Instead it is recommended to use the alternate bracketed syntax.
Add \
before any global class, function and constant (stdClass
in your example). Here is more information how to use namespaces.
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