Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $class_name = 'SomeClassName';
- $object = new $class_name;
- ?>
- $classname = 'SomeClassName';
- for ($x = 0; $x < 100000; $x++){
- $object = new $classname;
- }
- <?php
- class Test {
- function __construct($x) {
- echo $x;
- }
- }
- $class = 'Test';
- $object = new $class('test'); // echoes "test"
- ?>
- <?php
- $class = "Test";
- $args = array('a', 'b');
- $ref = new ReflectionClass($class);
- $instance = $ref->newInstanceArgs($args);
- ?>
- <?php
- $className = 'ClassName';
- $className::someStaticMethod(); //doesn't work
- ?>
- class Test {
- function testExt() {
- print 'hello from testExt :P';
- }
- function test2Ext()
- {
- print 'hi from test2Ext :)';
- }
- }
- $class = 'Test';
- $method_1 = "testExt";
- $method_2 = "test2Ext";
- $object = new $class(); // echoes "test"
- $object->{$method_2}(); // will print 'hi from test2Ext :)'
- $object->{$method_1}(); // will print 'hello from testExt :P';
Add Comment
Please, Sign In to add comment