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!
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.
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!!!
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.
Take a look in your php.ini file for the php version that is running.
I deleted public part and it works fine. it is weird! is that public really important in there!?
Related
I'm trying to install codeigniter bonfire. After clicking the install button on the create username screen, it takes a few moments and then it loads this page. I watched some tutorials on how to install bonfire so I know this isn't what I should be seeing.
Regardless, I updated the RewriteBase to /bonfire/ as it says..and now I'm getting this error when I try to go to localhost/bonfire/index.php
Parse error: syntax error, unexpected 'yield' (T_YIELD), expecting
identifier (T_STRING) in
/opt/lampp/htdocs/bonfire/bonfire/application/libraries/template.php
on line 305
Here's the code at line 305
public static function yield()
{
$output = '';
if (self::$debug) { echo 'Current View = '. self::$current_view; }
self::load_view(self::$current_view, NULL, self::$ci->router->class .'/'. self::$ci->router->method, FALSE, $output);
Events::trigger('after_page_render', $output);
return $output;
}//end yield()
I found this link on bonfire forums explaining the error.
Bonfire forums link
It says to use PHP 5.4 and that's what I'm using. My operating system is Linux Zorin and I'm using lampp, so I'm not sure if this could be a permissions issue.
thx in advance and please let me know if you need more info.
a bit late but hopefully help.
You can change the name for static function yield in cibonfire, something like this:
public static function yield()
to:
public static function yield_content()
this works perfectly to me.
I think in the LAMP the version of PHP is 5.5 + Something. IN PHP 5.5 there is a function name as yield so you have to downgrade your LAMP PHP version to 5.4 or modify in the Bonfire file system.
For change in Bonfire You can Go through this link and your problem has been solved.
https://github.com/illuminate/view/commit/d37abcecc7d79d00bf5f22b134d152ca765f26b2
You can also Review this link Laravel 4 syntax error out-of-the-box
After following the user guide instructions found here: http://ellislab.com/codeigniter/user-guide/general/cli.html I'm unable to run the test script via command line.
My controller located at /var/www/mysite/application/controllers/
class Tools extends CI_Controller {
public function message($to = 'World')
{
echo "Hello {$to}!".PHP_EOL;
}
}
In my browser I can access
http://mysite/tools/message/ben
And the function correctly outputs "Hello ben"
From terminal I should be able to run:
$ php index.php tools message "Ben"
My terminal should print: "Hello Ben"
However I get the following error:
PHP Fatal error: Class 'CI_Controller' not found in /var/www/mysite/system/core/CodeIgniter.php on line 233
My server is pretty standard; ubuntu LAMP. Codeigniter is pretty standard too and I have no problem running non CI scripts via command line
My PHP binary is only located in /usr/bin/php <-- This post suggests an issue running CI directly from usr/bin/php, however I'm not operating a shared PHP service, and I don't see why this would make a difference to how PHP executes a CI script.
Any help or just an indication on how to debug this would be greatly appreciated.
Thanks in advance.
Solved! (partly) the issue was CodeIgniters error logging.
In application/config/config.php, I modified the following config property:
$config['log_threshold'] = 0;
This disables logging, and allows $ php index.php to execute.
If anyone can explain why CI only shows this error on CLI PHP - might help anyone else who has this issue and needs it resolved with error logging on.
To solve error "Class 'CI_Controller' not found" try going to Application -> Config -> database.php then check the database details like hostname, username, password and database.
To Mijahn:
I had this same problem, and after about two hours of tracing through code to figure out the problem, it seems that there is some sort of conflict with loading the CI_Controller when utilizing the native PHP load_class function.
I worked around this issue by making the following changes to the Common.php file (hack, I know).
//$_log =& load_class('Log');
require_once('system/libraries/Log.php');
$_log = new CI_Log();
My logs then where created exactly like I wanted. Hope this hack helps.
This site says to run codeigniter from the command line, one must set the $_SERVER['PATH_INFO'] variable.
$_SERVER['PATH_INFO'] is usually supplied by php when a web request is made. However, since we are calling this script from the command line, we need to emulate this small part of the environment as a web request.
The answer provided in this Stack Overflow post worked for me.
Within system/core/CodeIgniter.php, on around line 75, change:
set_error_handler('_exception_handler');
to...
set_exception_handler('_exception_handler');
Other users have reported that this gave them a better backtrace with which to debug the underlying issue, but for me, this actually removed the problem altogether.
The following exception is thrown on my server:
Fatal error: Class 'My_Model_Bo_User_Agenda_Doctors' not found in...
Though in localhost everything is working fine.
I checked that everything was correctly uploaded; all the files are present and not corrupted. I also tried to upload several times. So this doesn't seem to be the problem.
Any idea why a class couldn't be found on the server ?
You don't say so in your question, but I suspect that you are developing on windows and hosting on Linux.
Windows is not case sensitive to path names, but Linux is! Check that:-
Doctors.php is not doctors.php
Agenda/ is not agenda/ .etc
Lastly check the class name in the class declaration is correct and correctly cased.
Do not just think to yourself, yes I've done that, go and check them carefully. Believe me, bitter experience has taught me this problem is always due to a trivial oversight like this.
I'm getting the below error on my server:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /nfs/c03/h03/mnt/53496/domains/chuggington.com/deploy/releases/20100908062138/system/application/models/home_model.php on line 5
However, the code works in a different part of the server (the development side). This is me trying to put it live.
Below is the code it is referring to:
<?php
class Home_model extends Model {
public function Home_model()
{
// model constructor
parent::Model();
}
function getCode(){
$ip_address = 'INET_ATON('.$_SERVER['REMOTE_ADDR'].')';
//echo $_SERVER['REMOTE_ADDR'];
$this->db->select('country');
$this->db->order_by('ip', 'desc');
$query = $this->db->get_where('ip2nation', array('ip <'=>$ip_address), '0,1');
//print_r($query->row('country'));
return $query->row('country');
}
}
?>
Can syslink cause this sort of error? There are no htaccess scripts interfering either.
Thanks
---EDIT---
I have run a phpinfo on the site and it's running php 5.2.6. I'll try the addhandler change and see if that works.
Just tried the addhandler and i'm still getting the same error.
Some hosts may offer both PHP4 and PHP5 environments and require you to choose one or the other, defaulting to PHP4. Our host requires a AddHandler php5-script .php line in the .htaccess file of directories that should use PHP5. Others may offer a switch in a control panel.
Consult your host's manual.
Remove "public". And put a phpinfo(); on top of that file. Find out what's wrong.
There's probably an alternative PHP4 interpreter installed, and whatever script accesses your class runs in that context.
Is there any other code in the same file? This error seems to me like another class or function hasn't been closed properly with a bracket } above. Or something of the kind.
I made this stupidly simple PHP file containing
<?php
class stuff {
private $var;
}
?>
and results in this error when run:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in . . . on line 4
To make things even more confusing, it functions normally on a different domain with the same host. Surely the folder and domain have nothing to do with whether class properties can be defined. What is going on here??
That's legal PHP code. I'd guess you're testing it in a machine that has PHP 4 installed. Support for PHP 4 has been discontinued for a long time; it's strongly recommended to upgrade.
Seems like PHP 4 is active on that particular domain/folder of yours.
It looks like php4.
put
<?php phpinfo();>
into a file and view it from a web browser. That will let you determine the version.
You mean a different domain hosted on the same server? It could be an error with your php installation.