【发布时间】:2015-03-27 16:59:48
【问题描述】:
伙计们,为什么 php 不读取我的类文件?我有这个结构:
- home.php
- stamp.php
- 类/class.stamp.php
- 类/class.text.php
home.php
<?php
echo "hello i'm the home page";
include 'class/class.stamp.php'
$stamp = new Stamp();
include 'class/class.text.php';
?>
class.text.php
<?php
$stamp->something('hello yes it is');
?>
class.stamp.php
<?php
class Stamp {
public function something($text);
echo $text;
}
}
?>
结果?没有!它说:
致命错误:在 /bla/bla/bla/ 中的非对象上调用成员函数。
但如果我这样做,它会起作用!
home.php
<?php
echo "hello i'm the home page";
include 'class/class.text.php';
?>
class.text.php
<?php
include 'class.stamp.php'
$stamp = new Stamp();
$stamp->something('hello yes it is');
?>
class.stamp.php
<?php
class Stamp {
public function something($text) {
echo $text;
}
}
?>
但是我不需要那个,请大家帮帮我:(
【问题讨论】:
-
include 'class.text.php';但正如你所写,它在目录中:class -
包含的文件与您正在加载的第一个脚本(您访问的页面)相关。因此,如果您正在加载
home.php,要获取需要指定class目录的类。即使您加载包含class/class.stamp.php的主页,其中包括class.text.php。stamp需要指定类文件夹,因为它与访问的页面home.php相关。 -
对不起,我的错误,我现在更新代码。但问题仍然存在。
-
@RavenJe 1.
include 'class/class.stamp.php'public function something($text); { -
是的...对不起,这是一个示例代码,我错过了一些东西,现在我再次编辑...问题仍然一样,抱歉。