Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #15405

Re: Syntax error help

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.datemas.de!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.php
Subject Re: Syntax error help
Date Thu, 04 Jun 2015 01:46:37 +0200
Organization solani.org
Lines 31
Message-ID <mko3kl$1sr$1@solani.org> (permalink)
References <super70s-8B1DCE.18194603062015@reader.albasani.net>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace solani.org 1433375189 1947 eJwNysEBwEAEBMCWzrGLcoLov4Rk3gOlsN0IGhab8AOvPJkqnT0Po6RtNEy9ln9cjsUtv4L3AwYwEF0= (3 Jun 2015 23:46:29 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Wed, 3 Jun 2015 23:46:29 +0000 (UTC)
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
X-User-ID eJwNwgERACAIBLBKj/AIcUSlfwS9jerie5rTjf2FqTfqcCUBqdDCqTtaehfSQmHgWEwyMB8PoxAz
In-Reply-To <super70s-8B1DCE.18194603062015@reader.albasani.net>
Cancel-Lock sha1:fK7KFAInEFGVlN+tBtTvQs71W4E=
X-NNTP-Posting-Host eJwNxMERACEIA8CWzEgClgMo/Zdwt4/lFtRuoozDyb74q14WXO6nYg4eqNhFqvICV+OW3Xr8ACxQEZI=
Xref csiph.com comp.lang.php:15405

Show key headers only | View raw


super70s wrote:

> I'm getting a parse error (Parse error: syntax error, unexpected '[' in 
> /home/sitename/public_html/videos/index.php on line 63) in the below 
> YouTube video search script.
> 
> I believe line 63 to be...
> $video = youtubeGetVideo($id)['snippet'];
> 
> This error showed up after I moved this script to a different server. I 
> think it might have something to do with the new server running a 
> version of PHP earlier than 5.4. Either that or there's a bracket or 
> semicolon that isn't closed, however it did work OK on the other server.
> 
> If anyone has any idea what could be causing this and a fix I'd really 
> appreciate it.

Indeed, this syntax is available only as of PHP 5.4.0: "Function array
dereferencing has been added, e.g. foo()[0]."[1]  For older versions
(which might better be avoided, because they are no longer supported),
you can get around the issue by assigning the function return value to
an auxiliary variable, and to access the desired element on that:

  $aux = youtubeGetVideo($id);
  $video = $aux['snippet'];

[1] <http://php.net/manual/en/migration54.new-features.php>

-- 
Christoph M. Becker

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Syntax error help super70s <super70s@super70s.invalid> - 2015-06-03 18:19 -0500
  Re: Syntax error help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-04 01:46 +0200
    Re: Syntax error help super70s <super70s@super70s.invalid> - 2015-06-03 20:30 -0500

csiph-web