Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.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 - Fatal编程技术网

Php 调用类本身的函数错误

Php 调用类本身的函数错误,php,Php,如何调用属于该类中同一类的函数 我有: class BaseConfig { public $page ; public $htmlRoot = 'assets/html/'; public function getPageTitle(){ echo $page = $_GET['p']; } public function getContent(){ $file = getPageTitle().'.php'; return readfile($htmlRoot.

如何调用属于该类中同一类的函数

我有:

class BaseConfig {

public $page ;
public $htmlRoot = 'assets/html/';

public function getPageTitle(){
    echo $page = $_GET['p'];
}

public function getContent(){
    $file = getPageTitle().'.php';
    return readfile($htmlRoot.$file);
}
}
我在调用时遇到以下错误

<?PHP Config::getContent();?>

Fatal error: Call to undefined function getPageTitle() in C:\Xit\xampp\htdocs\IMS3\assets\Config.php on line 17

致命错误:在第17行的C:\Xit\xampp\htdocs\IMS3\assets\Config.php中调用未定义的函数getPageTitle()
顺便说一下,我正在创建自己的简单框架


谢谢大家,$这不起作用,它只是说我不能在对象上下文之外使用它

“赛尔夫”工作得很好,谢谢

你能详细说明一下拉杜提到的安全漏洞吗



@S3Mi正在读取的文件只是html。在这个用例中,我所做的还差还是还可以?

您需要在函数名之前使用
$this->

$file = $this->getPageTitle().'.php';
如果该函数是
静态的
,那么在大多数情况下,您将使用
self::
而不是
$this->

$value = self::someStaticFunction();

如果函数是
静态的
也可能需要使用调用它,例如
静态::someStaticFunction()
。然而,这暗示了一个有问题的类设计,所以我只是为了完整性才提到它。

您需要在函数名之前使用
$this->

$file = $this->getPageTitle().'.php';
$file = $this->getPageTitle().'.php' ;
如果该函数是
静态的
,那么在大多数情况下,您将使用
self::
而不是
$this->

$value = self::someStaticFunction();
如果函数是
静态的
也可能需要使用调用它,例如
静态::someStaticFunction()
。然而,这暗示了一个有问题的类设计,所以我只是为了完整性而提到它

$file = $this->getPageTitle().'.php' ;
我看到您在单独的文件夹中有文件,我猜您没有任何关键/机密数据,但这并不能解决访问其他文件夹的问题

可以将$_GET['p']设置为“../index.php”,并获取php代码。这是一个很大的安全问题

我建议您阅读有关输入净化和验证的内容

决不要通过readfile()或任何传递原始内容的函数来提供.php文件。 .php文件应该由php解释。公开.php代码非常糟糕

我看到您在单独的文件夹中有文件,我猜您没有任何关键/机密数据,但这并不能解决访问其他文件夹的问题

可以将$_GET['p']设置为“../index.php”,并获取php代码。这是一个很大的安全问题

我建议您阅读有关输入净化和验证的内容

决不要通过readfile()或任何传递原始内容的函数来提供.php文件。 .php文件应该由php解释。公开.php代码非常糟糕