<?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.
精彩评论