Skip to content

Instantly share code, notes, and snippets.

@coodix
Last active December 22, 2015 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coodix/6537392 to your computer and use it in GitHub Desktop.
Save coodix/6537392 to your computer and use it in GitHub Desktop.
Example of usinf use statement with PHP namespaces
<?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