search

Home  >  Q&A  >  body text

Regarding creating objects, I don’t understand how to use get_class() to return the class name.

class dome{
}
$w =new dome();
$w1 =new $w();
echo get_class($w1);


Create a new class whose name is dome and then generate an object of $w. At this time, I use $w1 =new $w(); to create a new object instead of assigning a value. This is how I understand it. , which is equivalent to treating $w as a class, so a new object is generated, but using echo get_class($w1); the output is still dome, not $w. What is the principle? Because $w is not a class, its class is taken.

葫芦娃平衡盘葫芦娃平衡盘2705 days ago1079

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-08-07 11:04:12

    There is something wrong with the code. $w has already generated an object. If you try $w1 and then new it, it won’t work. You can try $w1 = clone $w

    reply
    0
  • 大家讲道理

    大家讲道理2017-08-07 09:35:18

    $w() is not a class

    reply
    0
  • Cancelreply