Last active
December 22, 2015 21:59
-
-
Save coodix/6537392 to your computer and use it in GitHub Desktop.
Example of usinf use statement with PHP namespaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// class User.php | |
namespace Billing; | |
class User { | |
... | |
} | |
// class Aggregator.php | |
namespace Billing\Aggregator; | |
class Aggregator { | |
... | |
} | |
// class Processor.php | |
namespace Billing\Aggregator; | |
class Processor { | |
... | |
} | |
// class Manager.php | |
namespace Billing\Aggregator\Details; | |
use Billing\User as User; | |
class Manager { | |
function ...(User $User) { // User -> \Billing\User | |
$Details = new Details($User); | |
} | |
} | |
// class Details.php | |
namespace Billing\Aggregator\Details; | |
// allow use only for root namespace Billing | |
use Billing\User as User; | |
use Billing\Aggregator\Aggregator as Aggregator; | |
use Billing\Aggregator\Processor as AggregatorProcessor; | |
class Details { | |
function ...(User $User, Aggregator $Aggregator) { // User -> \Billing\User, Aggregator -> \Billing\Aggregator\Aggregator | |
... | |
$Processor = new AggregatorProcessor(); // relative name mean class is from Billing | |
$FeatureUser = \Feature\User(); // absolute name every time when need class from another root namespace | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment