我有一个连接类,它应该为我连接到数据库,但是它不能工作。
connection.php -
<?php
require_once "config.php";
class connection{
public static $db_con;
public function __construct(){
$this->db_con = new mysqli($server_name, $user_name, $password, $database_name);
i
php中的"_“是什么,以及为什么它是一个未定义的有效函数。
# code will pass that check. and it will print "_"
if(function_exists("_"))
{
print f('_');
}
此外,当我尝试打印时(它可以工作,但会给我通知)
print _;
php通知我。
Notice: Use of undefined constant _ - assumed '_'
所以我使用常量函数,并尝试获取他的值,
print constant("_
我试图大致了解构造函数和PHP,但我在这里试图实现的是,用PI和FOUR_THIRDS作为类中的常量来计算圆的体积、直径和面积。
我的代码一直说常量存在错误,说明它们是未定义的,但我从php.net复制了方法。然后$radius也显示为一个未定义的变量,所以应该在类中添加$radius = 1;来定义它,这就是定义的意思吗?
<?php
class SphereCalculator {
const PI = 3.14;
const FOUR_THIRDS =4/3;
public function __construct($radius){
$this-
function CharField($len)
{
return "VARCHAR($len)";
}
class ArticleModel extends Model
{
public $name = CharField(100); // Error Here
}
当我用函数返回的值分配这样的公共属性时,它会引发错误:
PHP分析错误:语法错误,意外'(',期待',‘或';’在/var/www/test/db.php中
原因是什么?