, , . :
, . , .
:
class Phone {}
$classtype = 'Phone';
$phone = new $classtype();
var_dump($phone);
:
object(Phone)#1 (0) {
}
, ( "" ) , ). :
class Phone {}
$classtype = 'Phone';
$reflectionClass = new ReflectionClass($classtype);
$phone = $reflectionClass->newInstanceArgs();
var_dump($phone);
Phone , :
Phone.php
<?php namespace Contact;
class Phone {}
test.php
<?php
include 'Phone.php';
$classtype = 'Contact\Phone';
$phone = new $classtype();
var_dump($phone);
100%, , , . :
<?php namespace Foo;
use SomePackage\SomeClass as WeirdName;
$test = new WeirdName();
:
<?php namespace Foo;
use SomePackage\SomeClass as WeirdName;
$class = 'WeirdName';
$test = new $class();
PHP , , WeirdName - SomePackage\Someclass? , , , userland, .