[TYPO3-core] Creating aliases with the "use" operator

Jigal van Hemert jigal.van.hemert at typo3.org
Fri Oct 12 21:55:52 CEST 2012


Hi,

On 12-10-2012 21:24, Steffen Müller wrote:
> namespace TYPO3\CMS\Core\Log;
>
> use \TYPO3\CMS\Core\Log as Log;
>
> class Logger {
>
> 	public function debug($message, array $data = array()) {
> 		return $this->log(Log\LogLevel::DEBUG, $message, $data);
> 	}
> }
>

AFAIK you can use unqualified names if you are inside the namespace.

If inside namespace TYPO3\CMS\Core\Log you have classes LogLevel and 
Logger you can simply use LogLevel::DEBUG . PHP will first try to 
resolve this qualified name (not fully qualified!) inside the current 
namespace and \TYPO3\CMS\Core\Log\LogLevel::DEBUG is exactly what you're 
looking for.

Aliases are useful if you want to import a namespace which would lead to 
conflicts in resolving names.

http://www.php.net/manual/en/language.namespaces.rules.php

-- 
Jigal van Hemert
TYPO3 CMS Core Team member

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the TYPO3-team-core mailing list