doujiao9574 2013-03-14 13:58
浏览 27
已采纳

在php 5.3中使用ucfirst()函数返回一个解析错误[关闭]

I'm trying to add a ucfirst() function in my codeigniter controller so I'll get back a string with a first upper case letter. For some reason I keep getting a parse error:

Parse error: syntax error, unexpected '(', expecting ',' or ';' in ... on line 7 (the line where my ucfirst is).

Trying to change ucfirst() to ucfirst(strtolower($database)) or to ucwords($database) returning the same result.

My code is:

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

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

2条回答 默认 最新

  • dscdttg4389 2013-03-14 13:59
    关注

    From php doc

    declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

    You should initialise $model property in class constructor

    public function __construct()
    {
       // I guess you'll need to call parent constructor as well
       parent::__construct();
       $this->model = ucfirst($this->database) . '_model';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记