Sunday 15 August 2010

php - The use of "use" -



php - The use of "use" -

i playing around ide , noticed when utilize "fix code" alternative on class adds bunch of lines on top of next type

use someclass; utilize \ano\therclass; utilize iface; ...

i wondering purpose of this, since classes going loaded on demand, there need explicitly declare classes going used?

when u create class, name it's bundle keyword namespace

<?php /** * cacheexception.php */ namespace doctrine\orm\cache; class cacheexception extends exception {}

elsewhere use can import 1 class package:

use doctrine\orm\cache\cacheexception; throw new cacheexception('failed cache');

also use imports overal bundle it's classes:

use doctrine\orm\cache; throw new cacheexception('failed cache');

more @ http://php.net/manual/en/language.namespaces.importing.php

php oop use

No comments:

Post a Comment