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


Groups > comp.lang.php > #15405

Re: Syntax error help

From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.php
Subject Re: Syntax error help
Date 2015-06-04 01:46 +0200
Organization solani.org
Message-ID <mko3kl$1sr$1@solani.org> (permalink)
References <super70s-8B1DCE.18194603062015@reader.albasani.net>

Show all headers | 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