PHP对象_construct函数 [英] PHP object _construct function
本文介绍了PHP对象_construct函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码
<!doctype html>
<head>
<meta charset = "utf-8">
<title>Objects</title>
</head>
<body>
<?php
class firstClass
{
function _construct($param)
{
echo "Constructor called with parameter $param";
}
}
$a = new firstClass('one');
?>
</body>
</html>
当我运行此代码时,浏览器中没有任何输出,我所遵循的教程说此代码应输出使用参数apples调用的构造函数",这是什么问题?
When i run this code nothing is outputted in the browser, the tutorial i am following says this code should output "Constructer called with parameter apples", what is the problem?
推荐答案
构造函数应为带有两个下划线的__construct().
The constructor should be __construct() with two underscores.
http://php.net/manual/en/language.oop5. decon.php
它将在您的代码中输出用参数1调用的构造函数".
And it will output "Constructor called with parameter one" in your code.
这篇关于PHP对象_construct函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文