我在PHP代码中遇到了这个问题:
class Core {
public function start()
{
require("funk/funks/libraries/uri.php");
$this->uri = new uri();
require("funk/core/loader.php");
$this->load = new loader();
if($this->uri->get_segment(1) != "" and file_exists("funk/pages/".$uri->get_segment(1).".php")){只有一段代码
我能解释的最好的方法是,它是一个调用另一个类(uri.php)的类,并且我得到了错误:致命错误:调用第11行中一个非对象上的成员函数get_segment() (if($this->uri->get_段(1)部分)。
我经常遇到这个问题,这真的困扰着我。
图书馆代码是:
<?php
class uri
{
private $server_path_info = '';
private $segment = array();
private $segments = 0;
public function __construct()
{
$segment_temp = array();
$this->server_path_info = preg_replace("/\?/", "", $_SERVER["PATH_INFO"]);
$segment_temp = explode("/", $this->server_path_info);
foreach ($segment_temp as $key => $seg)
{
if (!preg_match("/([a-zA-Z0-9\.\_\-]+)/", $seg) || empty($seg)) unset($segment_temp[$key]);
}
foreach ($segment_temp as $k => $value)
{
$this->segment[] = $value;
}
unset($segment_temp);
$this->segments = count($this->segment);
}
public function segment_exists($id = 0)
{
$id = (int)$id;
if (isset($this->segment[$id])) return true;
else return false;
}
public function get_segment($id = 0)
{
$id--;
$id = (int)$id;
if ($this->segment_exists($id) === true) return $this->segment[$id];
else return false;
}
}
?>发布于 2010-05-31 20:31:05
您对get_segment()的调用不一致。
在一种情况下,您调用$this->uri->get_segment(),根据前面的代码,这是正确的。第二次调用$uri->get_segment时,它丢失了$this->,因此不是有效的对象。
https://stackoverflow.com/questions/2945784
复制相似问题