当前位置:主页 > JavaScript >

javascript与PHP动态往类中添加方法对比

栏目:JavaScript 来源: 微信小程序开发网 阅读: 2018-03-26

var a = function(){ } var my_a = new a() my_a.say = function(){ console.log('hello') } my_a.say()

b. 输出:

hello

2. PHP:

a. 代码:

<?php class a{ } $$a = new a(); $$a->say = function(){ echo "hello"; }; $$say = $$a->say; $$say();