【问题标题】:PHP cannot import class filePHP无法导入类文件
【发布时间】:2014-12-31 23:23:53
【问题描述】:

我在同一个目录下有这两个php文件:

index.php

<?php

    echo "before";

    require('Parser.php');

    echo "after";
?>

Parser.php

<?php

    /**
    * Class Parser
    */
    class Parser
    {

        private $url;

        function __construct($url)
        {
            $this->url = $url;
        }



        public function getUrl(){
            return $this->url;
        }

        public functionsetUrl($url){
            $this->url = $url;
        }

    }

?>

我需要导入 Parser 文件,因为我必须在我的索引文件中使用这个类,但我不能。

导入此类时出现问题,因为如果我尝试访问 index.php,我只能看到第一个打印:before

我不知道问题出在哪里但是很奇怪,我的文件很简单。

我的 php 版本是 5.6,我使用 MAMP 作为 Web 服务器。

有人可以帮助我吗? 谢谢

【问题讨论】:

  • 开启错误。你可能有一个Fatal Error

标签: php class oop import


【解决方案1】:

您的 Parser 课程中有错字:

 public functionsetUrl($url){

应该是

 public function setUrl($url){

【讨论】:

  • 这就是为什么您使用 IDE 在您键入时检测这些类型的问题。
猜你喜欢
  • 1970-01-01
  • 2017-02-12
  • 1970-01-01
  • 1970-01-01
  • 2017-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-25
相关资源
最近更新 更多