开发者

How I am able to do following in Php, it is not throwing any error, please explain

开发者 https://www.devze.com 2023-03-15 16:48 出处:网络
<?php class test { func开发者_如何学运维tion test_print($myvar) { echo $myvar; } } $my_test = new test();
<?php

 class test
 {

   func开发者_如何学运维tion test_print($myvar)
   {
      echo $myvar;
   }
 }

  $my_test = new test();
  $my_test->a = 3;
  $my_test->test_print($my_test->a);

?>

How I am able to create a new variable dynamically outside class, this is not Oops.. please correct if I am missing something.


PHP allows dynamic properties, like other dynamic languages, such as JavaScript.

It can be useful, but generally is not used an awful lot in PHP.

There was a blog article I found, that shows how you can prevent dynamic properties if you really desire it gone.

Though it is faster to use dynamic properties directly than using the __get() and __set() magic methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消