What is going on with my PHP class variable? - php

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.

Related

yii2 project running errors

I am installed yii2 advanced template using composer all are working fine.
System have php7.1.5. Whenever i copy advanced folder in another system it throw syntax error in TestCase.php like below
Parse error: syntax error, unexpected '?' in \advanced\vendor\phpunit\phpunit\src\Framework\TestCase.php on line 822
line 822 is $configurationFilePath = $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] ?? '';
That another system have php5.6.8
So, i am directly install yii2 advanced in that system and it is working fine.
I am check TestCase.php the file have lot of differences and the particular line also changed like below
$configurationFilePath = (isset($GLOBALS['__PHPUNIT_CONFIGURATION_FILE']) ? $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] : '');
So i want to know what is going here.My question is not clear please let me know.Thanks in advance
PHP operator ?? is available since PHP7, so u can't expect, that code from PHP7 will work on server with PHP5.
PHP 7 - Null coalescing operator

Parse error building website with CakePHP

I recently did the blog tutorial for CakePHP, as is found here: http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/blog.html
I have CakePHP version 2.8.5, and WampServer with Apache 2.4.9, PHP 5.5.12 and MySQL 5.6.17, and got the blog running on localhost/.
I am now trying to upload the blog to a server online, and have used SmartFTP to upload files to the folder public_html on a free web server online, but when I visit the domain, I receive:
Parse error: syntax error, unexpected T_STATIC, expecting T_STRING or T_VARIABLE or '$' in /home/a3087838/public_html/lib/Cake/Core/App.php on line 221
Line 221 is:
if (!empty(static::$legacy[$type])) {
which is part of:
public static function path($type, $plugin = null) {
if (!empty(static::$legacy[$type])) {
$type = static::$legacy[$type];
}
I have seen similar questions asked online, but the solution seems to be that PHP version 5.3 or greater is required as prior versions don't support late static binding, but my version is 5.5.12, so I shouldn't have that problem.
I tried replacing the word static with self, but the error then just reiterates itself for later lines containing static. I repeated this down to line 282 and it's behaviour didn't change. I could replace all other instances of static with self, but that will take a while and I expect there is a better solution that I am missing, if that is even a solution. I am inexperienced and any help would be appreciated.

Laravel 4 syntax error out-of-the-box

I just installed Laravel 4 (Illuminate) and as I opened the index.php file in a browser, I was met with this error:
Parse error: syntax error, unexpected 'yield' (T_YIELD), expecting identifier (T_STRING) in /www/Laravel4/vendor/illuminate/view/src/Illuminate/View/Environment.php on line 339
I have fixed the permissions for the meta folder, and installed all the dependencies through Composer. I am running PHP version 5.5.0alpha2 on OSX 10.8.2.
That's because yield became a language construct in PHP 5.5 (used in Generators) - but someone decided that it's a good idea to use this short word to name a function:
public function yield($section)
{
return isset($this->sections[$section]) ? $this->sections[$section] : '';
}
Downgrade to PHP 5.4 (after all, it's the current mainstream version, 5.5 is not even in beta yet) and it should work fine.

Getting what appears to be a PHP4 error on my PHP5 server

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.

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

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!?

Categories