Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
包含和类PHP_Php_Class_Oop_Include - Fatal编程技术网

包含和类PHP

包含和类PHP,php,class,oop,include,Php,Class,Oop,Include,伙计们,为什么php不读取我的类文件?我有这样的结构: home.php stamp.php class/class.stamp.php class/class.text.php home.php class.text.php class.stamp.php 结果如何?没有什么它说: 致命错误:对/bla/bla/bla中的非对象调用成员函数something/ 但如果我做了那样的事,它就行了 home.php class.text.php class.stamp.php 但我不需要,请大家帮我

伙计们,为什么php不读取我的类文件?我有这样的结构:

home.php stamp.php class/class.stamp.php class/class.text.php home.php

class.text.php

class.stamp.php

结果如何?没有什么它说:

致命错误:对/bla/bla/bla中的非对象调用成员函数something/

但如果我做了那样的事,它就行了

home.php

class.text.php

class.stamp.php


但我不需要,请大家帮我:

检查问题是否出在目录上

您说过它可以与class.stamp.php一起使用,但不应该是class/class.stamp.php吗?问题是,如果你的主页位于某个文件夹中,那么在同一个文件夹中,你应该有folder类,与Home.php文件相邻

我还遇到了未实例化对象的问题,所以请确保在每个范围中都包含它。要帮助您捕获错误,请使用

require "class/class.stamp.php";//Throws an error if it can't find the file.
require_once "class/class.stamp.php";//Bad practice

如果require不能帮助您解决问题,请发布所有内容。

包括“class.text.php”;但正如您所写的,这是在目录中:类包含的文件是相对于您正在加载的第一个脚本,您访问的页面。因此,如果您正在加载home.php,要获取类,需要指定类目录。即使您加载home,其中包括class/class.stamp.php,其中包括class.text.php。stamp需要指定类文件夹,因为它与访问的页面home.php相对。对不起,我的错误,我现在更新代码。但问题仍然存在。@RavenJe 1。包括“class/class.stamp.php”是。。。伙计们,对不起,这是一个示例代码,我错过了一些东西,现在我再次编辑。。。问题还是一样对不起。
<?php

$stamp->something('hello yes it is');

?>
<?php

class Stamp {
  public function something($text);
      echo $text;
  }
}

?>
<?php

echo "hello i'm the home page";    
include 'class/class.text.php';

?>
<?php

include 'class.stamp.php'
$stamp = new Stamp();
$stamp->something('hello yes it is');

?>
<?php

class Stamp {
  public function something($text) {
      echo $text;
  }
}

?>
require "class/class.stamp.php";//Throws an error if it can't find the file.
require_once "class/class.stamp.php";//Bad practice