PHP可以在定义变量之前使用它们吗?
在php手册中 我看到这样的代码:PHP可以在定义变量之前使用它们吗?,php,Php,在php手册中 我看到这样的代码: $stmt->bind_param('sssd', $code, $language, $official, $percent); $code = 'DEU'; $language = 'Bavarian'; $official = "F"; $percent = 11.2; /* execute prepared statement */ $stmt->execute(); 没有php不能在编写声明之前使用变量 显然,在值存在之前,没有任何
$stmt->bind_param('sssd', $code, $language, $official, $percent);
$code = 'DEU';
$language = 'Bavarian';
$official = "F";
$percent = 11.2;
/* execute prepared statement */
$stmt->execute();
没有php不能在编写声明之前使用变量 显然,在值存在之前,没有任何语言能够输出它。方法存储对
$code
、$language
、$official
和$percent
变量值的引用。引用存储在$stmt
对象中
然后,当您给出变量值时,$stmt
对象已经知道在哪里查找值
我们可以自己创建一个类来实现这一点:
class Play {
protected $reference;
public function bind( & $variable) {
$this->reference = &$variable;
}
public function show() {
echo "{$this->reference}<br>\n";
}
}
是的,这是可能的。这已经讨论过了,或者
$play = new Play;
$play->bind($string);
$string = 'Hello!';
$play->show();
$string = 'World!';
$play->show();