+ 2
How to use namespaces in PHP classes?
also how to get class from php plugins in my namespace?
2 Answers
+ 2
Syntax for extending classes in namespaces is still the same.Â
Lets call this Object.php:Â
<?phpÂ
namespace com\rsumilang\common;Â
class Object{Â
   // ... code ...Â
}Â
?>Â
And now lets create a class called String that extends object in String.php:Â
<?phpÂ
class String extends com\rsumilang\common\Object{Â
   // ... code ...Â
}Â
?>Â
Now if you class String was defined in the same namespace as Object then you don't have to specify a full namespace path:Â
<?phpÂ
namespace com\rsumilang\common;Â
class String extends ObjectÂ
{Â
   // ... code ...Â
}Â
?>Â
Lastly, you can also alias a namespace name to use a shorter name for the class you are extending incase your class is in seperate namespace:Â
<?phpÂ
namespace com\rsumilang\util;Â
use com\rsumlang\common as Common;Â
class String extends Common\ObjectÂ
{Â
   // ... code ...Â
}Â
?>Â
source: http://php.net/manual/en/language.namespaces.basics.php
+ 2
To declare a namespace, use the namespace command followed by the name of the namespace to create. Nothing should be placed before, whether it's HTML or just a line break. No instructions must be written before the namespace declaration (except the declare statement).
SIMPLE EXAMPLE:
--------------------------------
<?php
namespace MonNamespace;
function strlen()
{
echo 'Hello world !';
}
?>