__construct() { issue for PHP4 and PHP5. maybe an another reason

耗尽温柔 提交于 2019-12-11 21:55:41

问题


I have weird issue with CodeIgniter,

here is a start part of my controller

class Home extends Controller
{
    /** 
    * Constructor
    */ 
    public function __construct() {
        parent::Controller();

    }

...

everything is working fine at localhost, but when I try same at server, I come cross with an error like below:

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home3/blabla/public_html/blablabla/applications/frontend/controllers/home.php on line 22

I researched and people say it is about PHP4.. it should be PHP5. but my server has PHP5 on. what can be the reason?

appreciate helps! thanks a lot!


回答1:


It really sounds like the interpreter is stumbling on the public keyword which it doesn't expect, which is an indication of/problem with the site running on PHP4.

Make sure you're echoing the PHP version in the site itself, not just looking it up in some control panel.

Check if there are any .htaccess directives that may change the default handler to PHP4.

Sometimes the host may default to PHP4 for .php files and PHP5 only for .php5 files.




回答2:


I'm so sorry! I dont know how come, but Bluehost info panel says PHP 5 is active. and i just believed that. when I make a php_info(); page just in case, i saw actually it is php 4 :/

I updated server for PHP5 and now everything is fine.

I'm sorry for messing. and thanks all you for great support!!!




回答3:


Are you having the same problem with the other functions in the class as well? because, as far as i know, you can't make a constructor public or private. It should be "function __construct()" only.




回答4:


Take a look in your php.ini file for the php version that is running.




回答5:


I deleted public part and it works fine. it is weird! is that public really important in there!?



来源:https://stackoverflow.com/questions/1232601/construct-issue-for-php4-and-php5-maybe-an-another-reason

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!