Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php $obj=';类名';$obj=newclassname()_Php - Fatal编程技术网

Php $obj=';类名';$obj=newclassname()

Php $obj=';类名';$obj=newclassname(),php,Php,嗨,朋友们,请澄清以下代码的区别: <?php class student { function stu() { echo "Hi Friends"; } } //difference between this $s = new student(); $s -> stu(); //and this $s1 = 'student'; $s1 -> stu(); $s=新学生()创建类student的新实例,并将其存储到$s变量中 $s1='

嗨,朋友们,请澄清以下代码的区别:

<?php
class student {
    function stu() {
        echo "Hi Friends";
    }
}

//difference between this
$s = new student();
$s -> stu();

//and this
$s1 = 'student';
$s1 -> stu(); 
$s=新学生()
创建类
student
的新实例,并将其存储到
$s
变量中

$s1='student'
将字符串
student
存储到变量
$s1
中。最后一行
$s1->stu()给出了一个错误,因为您无法对字符串调用方法

我给你的建议是买一本PHP入门书并阅读,这样你就能掌握基础知识。

$s=new student()
创建类
student
的新实例,并将其存储到
$s
变量中

$s1='student'
将字符串
student
存储到变量
$s1
中。最后一行
$s1->stu()给出了一个错误,因为您无法对字符串调用方法

我给你的建议是买一本PHP入门书并阅读,这样你就能掌握基础知识。

你的意思一定是:

$instance = new myclass();

如果这就是你的意思,那么就没有区别了。当您希望动态生成类名时,可以使用后者

你一定是说:

$instance = new myclass();


如果这就是你的意思,那么就没有区别了。当您希望动态生成类名时,可以使用后者

谢谢Jan Hancic surly我会做的谢谢Jan Hancic surly我会做的。