Well, I'm transferring a little web server from one computer to other, on the 'other' computer I cannot a more updated version of PHP,
I just have to add my files through ssh and that's all, when I load my webpage it says explicitly:
The error is showing on a Debian with PHP 5.4.27 squeeze, the webserver comes from an Ubuntu with PHP 5.4.16 oneiric
Parse error: syntax error, unexpected '[' in ~directory~ on line 38
This is the line 38.
$VALUE=$DB->query("a nice sentence")->fetch()[0];
So, i was pretty surprised because PDO was accepted since PHP 5.1, so, i look deeper and i found the possible error, you can't simply do ->fetch()[0], you must separate it in order to be "processed",
However, I have transport this server with this information before, so i really don't know if it's something on the configuration of PHP or maybe the version by itself 5.4.X? You guys know any hint? As I said, i can't just install other updated version of PHP5, what do you recommend?
Have a nice night.
Edit: updated to the issue on the PHP 5.4 now
The error seems triggered by the array dereferencing. This was added in PHP 5.4.. Not sure how you made that work in 5.3.6
http://nl3.php.net/language.types.array.php
To workaround you could try
$VALUE = $DB->query("a nice sentence")->fetch();
echo $VALUE[0];
PHP Version on my ubuntu (where it works):
PHP Version 5.4.16
PHP Version on the Debian (where it does not work):
PHP Version 5.4.27-1~dotdeb.0
This version number was extracted by using phpinfo(); on the index page.
Apparently, the error was solved by JUST changing the first issue line (the other hundreds of codes that had that wasn't necessary to change, what i believe to be a little weird).
$VALUE = $DB->query("a nice sentence")->fetch()->offset(0);
Related
I am trying to access an element of an array in PHP using the following method:
$test = $this->Student->find('first',array('conditions',array('Student.student_table_id'=>1)))['Student']['student_id'];
It seems to work well on a slightly newer version of XAMPP, but when I try to use that syntax on another machine with an older version of XAMPP for Mac OS X 1.7.3 installation, it throws me to a Server not found page. I don't know if it something to do with my XAMPP configuration or something else..
Also, this behavior, i.e. redirection to a server not found page, happens whenever there is a syntax error.
Mind you, both machines support the minimum requirements of CakePHP.
From the comment..
the PHP Version on the problematic machine is 5.3.1
That is because you are trying to use a new feature of PHP 5.4 , called the function array dereferencing.
How to fix ?
Break down your code like this.
$test = $this->Student->find('first',array('conditions',array('Student.student_table_id'=>1)));
$test1 = $test['Student']['student_id'];
I have:
on my pc:wamp server (apache+php-5.4.3+mysql)
on my vps:nginx+php5-fpm+mysql(all latest in the ubuntu 64 bit server repository).
recently I have reinstalled the whole vps
my problem is,
statement like this:
function foo($arr){
return $arr;
}
foo(['foo1','foo2','foo3'])
works on my pc, and used to work on the server (same installation) but now it gives
an error such as:
Parse error: syntax error, unexpected '[' in /home/Websites/Domains/squazza/php/db.php
on line 261
(replacing the [ ] with Array( ) does fix the problem)
now I assume that this problem is related to php.ini so i am asking what setting could possibly be affecting this kind of behavior and why?
If you look at the documentation that short syntax is only avaible in php 5.4+ I suspect your php versions are different.
This list of new features in PHP5.4 maybe of some use to you.
You're probably not using PHP 5.4. Run phpinfo() in your script and check it. And remember, you can have different PHP version in CLI mode.
As pointed out by #piddl0r, the short array syntax ([ 1, 2, 3 ]) was added in PHP 5.4. You'll note from The Ubuntu Package Archive that Ubuntu 12.04 - Precise Pangolin - only provided PHP 5.3.10; PHP 5.4.6 was provided in the next release, Quantal. To check your version of PHP, use phpinfo() or php --version on the command line.
I'm trying to install the mssql module for PHP on a server running CentOS 5.8 and PHP 5.3.5. I was able to get it working on the dev server which runs CentOS 5.2 and PHP 5.2.6, and everything seems to match up (FreeTDS installed, module in the modules folder, extension=mssql.so added to php.ini). However, the plugin won't load; doesn't show up in phpinfo() and I get an undefined function error on the test script.
Also of note: phpinfo() lists '--with-mssql=shared,/usr' under the configure command, which is really confusing me.
Solved. Not 100% what the fix was, but I'm pretty sure this was what fixed it.
First off, it probably didn't help I was trying to compile from a copy of php 5.3.16 instead of 5.3.6. Even then, I was running into errors trying to compile it. I found an fix that said to remove this line from php_mssql.h in the folder after it's phpized:
typedef unsigned char *LPBYTE;
I was then abe to do make && make install and it loads with no errors now.
on my server (Centos5) i have PHP 5.2, i'm unable to update it, i read somewhere that PHP 5.4 won't work on Centos5, didn't inspect enough as i am in the middle of a lot of projects, anyways, here is the syntax :
$data['trees'] = (new Tree())->where('parent_id',0)->get();
On my WAMP it runs on PHP 5.4.3, on the server it gives me the following error:
Parse error: syntax error, unexpected T_OBJECT_OPERATOR
Support for accessing instance members directly after a new expression was introduced in PHP 5.4 (finally). Note that the parentheses are required around the new expression, as in your given line of code, or it won't work.
I haven't heard of any particular server configurations or platforms where this won't work when running PHP 5.4. If it causes an error on a server where PHP 5.4 is installed, it's likely that's not the version that's interpreting your script (check your server config, .htaccess, and INI directives).
I have installed wampserver on my pc. I unzipped the cake php installation files in the "www" folder of wampserver. Now, when I try to run- "http://localhost/cakephp", I get a whole list of errors along with the cake php getting started page. Here are some of the errors:
Deprecated: Assigning the return value of new by reference is deprecated in
D:\wamp\www\cakephp\cake\libs\inflector.php on line 131
Deprecated: Assigning the return value of new by reference is deprecated in
D:\wamp\www\cakephp\cake\libs\configure.php on line 136
Deprecated: Assigning the return value of new by reference is deprecated in
D:\wamp\www\cakephp\cake\libs\configure.php on line 226
Deprecated: Assigning the return value of new by reference is deprecated in
D:\wamp\www\cakephp\cake\libs\configure.php on line 906
How do I fix this? I got similar errors for codeignite.
Which version of PHP are you running ?
To get E_DEPRECATED errors, it must be PHP 5.3 (which is quite recent) -- and I think the last version of WampServer uses this one.
See :
Predefined Constants
PHP 5.3.0 Release Announcement
As it's pretty recent and brought lots of new stuff, you might run into some kind of troubels (you actually did) with PHP 5.3.... Especially if the software you used is not compatible with it yet.
You might want to downgrade to the previous version of WampServer...
Or you could try lowering the error_reporting level (see also error_reporting), to not get those warnings.
But if you are getting those, you'll probably run into other problems as well...
Actually, after a rapid search into CakePHP's Trac, I found at least those :
Ticket #6026 : php 5.3 needs error_reporting(E_ALL & ~E_DEPRECATED);
Ticket #6500 : PHP 5.3 incompatibility
None of those is solved... So it seems CakePHP is really not ready for PHP 5.3... (It's probably not the only Framework in this situation btw -- Zend Framework v 1.9 which went out couple of days ago is the first version that officially supports PHP 5.3, for instance)
If you want to work with CakePHP, so, you'll probably have to use PHP 5.2.x (like 5.2.9 or 5.2.10).
You're actually not the only one in your situation, it seems... Too bad, as there are pretty nice things in PHP 5.3...
hi I faced the same problem. I have easyphp installed and the latest easyphp is also using php version 5.3. I downloaded cakephp stable version : Release: 1.2.4.8284 Stable. When i opened the web page, i also got the same 'depricated' notices. I also tried mangling with the 'error_reporting' section with no luck.
As I didn't want to downgrade my php 5.3 to an earlier version, I tried CakePHP 1.3-dev. And the problem was fixed.
I am also having the same problem.....I downgraded wamp5 2 to wamp 1.6.0...Now its working perfect
I had similar issue and I installed the 1.3.0-beta and the problem went away...
e
I tried one solution given by Pascal:
https://trac.cakephp.org/ticket/6026
applied this patch and in my case this helped. Thx
I had also same problem but I got resolve by changing in httpd.conf and php.ini
My changes are here-
in httpd.conf
replace
#LoadModule rewrite_module modules/mod_rewrite.so
to
LoadModule rewrite_module modules/mod_rewrite.so
and in tab Directory "{yourdirectoryname}:/wamp/www/">
replace
Order Deny,Allow
Deny from all
to
Order Allow,Deny
Allow from all
in php.ini
make curl ext on. there is no need to run but you should do :)
extension=php_curl.dll
My server and php configuration was
Apache Version : 2.2.17, PHP Version : 5.3.4