好的,我不确定100%这里发生了什么,但我认为它与我试图包含一个类使用PHP的“包括( $文件)“功能。类别变量不停留设置(PHP)
功能导入看起来是这样的:
<?php
function import($file) {
global $imported; $imported = true;
$home_dir = "C:/xampp/htdocs/includes/";
if (file_exists($home_dir.$file.".php")) {
include_once($home_dir.$file.".php");
}
$imported = false;
}
?>
我要做的就是调用下面的PHP在我的index.php文件:
<?php
import("php.buffer");
$out = new StringBuffer;
$out->write("test?");
echo "'".($out->get())."' <- Buffer String Should Be Here";
?>
的php.buffer.php文件看起来像这样:
<?php
class StringBuffer {
public $buffer = "";
public function set($string) {
if (!isset($buffer)) { $buffer = ""; }
$buffer = $string;
}
public function get() {
if (!isset($buffer)) { $buffer = ""; }
return $buffer;
}
public function write($string) {
if (!isset($buffer)) { $buffer = ""; }
$buffer = $buffer.chr(strlen($string)).$string;
}
public function read() {
if (!isset($buffer)) { $buffer = ""; }
$return = "";
$str_len = substr($buffer,0,1); $buffer = substr($buffer,1,strlen($buffer)-1);
$return = substr($buffer,0,$str_len); $buffer = substr($buffer,$str_len,strlen($buffer)-$str_len);
return $return;
}
public function clear() {
$buffer = "";
}
public function flushall() {
echo $buffer;
$this->clear();
}
public function close() {
return new NoMethods();
}
}
?>
当我创建新的StringBuffer类我没有得到任何错误,所以我知道它确实是我包括我的文件。
你面临什么问题? – 2012-03-28 08:41:10