Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.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
在PHP5.3中使用ucfirst()函数返回解析错误_Php_Codeigniter_Parsing_Ucfirst - Fatal编程技术网

在PHP5.3中使用ucfirst()函数返回解析错误

在PHP5.3中使用ucfirst()函数返回解析错误,php,codeigniter,parsing,ucfirst,Php,Codeigniter,Parsing,Ucfirst,我试图在我的codeigniter控制器中添加一个ucfirst()函数,以便返回一个带有第一个大写字母的字符串。出于某种原因,我一直收到一个解析错误: 分析错误:语法错误,第7行(我的第一行)的…中出现意外的“(”,应为“,”或“;” 尝试将ucfirst()更改为ucfirst(strtolower($database))或ucwords($database),返回相同的结果 我的代码是: defined('BASEPATH') OR exit('No direct script acces

我试图在我的codeigniter控制器中添加一个ucfirst()函数,以便返回一个带有第一个大写字母的字符串。出于某种原因,我一直收到一个解析错误:

分析错误:语法错误,第7行(我的第一行)的…中出现意外的“(”,应为“,”或“;”

尝试将ucfirst()更改为ucfirst(strtolower($database))或ucwords($database),返回相同的结果

我的代码是:

defined('BASEPATH') OR exit('No direct script access allowed');

class Somecontroller extends CI_Controller {
    private $database = "some_database";
    private $model = ucfirst($this->database)."_model";
    ...
}

声明可能包括一个初始化,但这个初始化必须是一个常量值——也就是说,它必须能够在编译时进行计算,并且不能依赖于运行时信息才能进行计算

您应该在类构造函数中初始化
$model
属性

public function __construct()
{
   // I guess you'll need to call parent constructor as well
   parent::__construct();
   $this->model = ucfirst($this->database) . '_model';
}

声明可能包括一个初始化,但这个初始化必须是一个常量值——也就是说,它必须能够在编译时进行计算,并且不能依赖于运行时信息才能进行计算

您应该在类构造函数中初始化
$model
属性

public function __construct()
{
   // I guess you'll need to call parent constructor as well
   parent::__construct();
   $this->model = ucfirst($this->database) . '_model';
}

您应该使用$this->database并在构造函数中赋值

public function __construct()
{
   // I guess you'll need to call parent constructor as well
   parent::__construct();
   $this->model = ucfirst($this->database) . '_model';
}
比如:

function __construct()
{
   $this->model = ucfirst($this->database) . "whatEver";
}

您应该使用$this->database并在构造函数中赋值

public function __construct()
{
   // I guess you'll need to call parent constructor as well
   parent::__construct();
   $this->model = ucfirst($this->database) . '_model';
}
比如:

function __construct()
{
   $this->model = ucfirst($this->database) . "whatEver";
}

你说得对!我修正了我的错误,但仍然出现语法错误…查看我的更改…使用构造函数…将其移动到我的构造函数,但仍然出现parase错误:语法错误,意外的T_PRIVATE@Lior使用
private$model;
在构造函数之前声明变量,并直接在构造函数中使用它使用
$this->model
,您不需要将其重新声明为
private
thereMarko,谢谢!!!我在顶部声明变量并在构造函数中使用它们,然后…它工作了!谢谢!您是对的!我修复了我的错误,但仍然会收到解析错误…查看我的更改…使用构造函数…将其移动到我的构造函数中,但仍然会出错parase错误:解析错误:语法错误,意外错误_PRIVATE@Lior使用
private$model;
在构造函数之前声明变量,并在使用
this->model
的构造函数中直接使用它,您不必重新声明为
private
thereMarko,谢谢!!!我在顶部声明变量,并在我的构造函数和…它工作了!谢谢!谢谢!问题按你说的解决了。谢谢!问题按你说的解决了。