Avatar

Report about an error with the notation of an object (Bugs)

by Auge ⌂ @, Friday, February 17, 2017, 17:43 (183 days ago)

Hello

I got an error report via e-mail, that I will cite in extracts here. I can't name the reason because I can't find a doc about this special case.

Begin of the cite from the report.

We were in a process to update my little forum package to 2.4 but manual
installation throws following error :
Parse error: syntax error, unexpected '[' in
/{PATH}/litforum24/includes/functions.inc.php on line 2675

I guess this is due to PHP version. It does not work on 5.2 and 5.3. It
works well on PHP 5.4+

End of the cite. I linked to the code and here it is.

 
   $release = (object) [   // <== here the error occurs
    'title'   => (string)$title[0],
    'content' => (string)$content[0],
    'version' => (string)$lastVersion,
    'uri'     => $baseURI . (string)$releaseURI[0]->href
   ];

I can't confirm or negate the assumption that it has to do with the PHP version. All examples of the (object)-notation, I found on php.net had another syntax with the function array. I have no clue, if it has to do with the error.

$var = (object) array('title' => (string)$title[0],);

On the other hand, the PHP versions 5.2 and 5.3, where the error occurs, are ancient and outdated nowadays. We have always to check the code for the use of functions, that are introduced in PHP in newer versions. I can't believe, that there is no function and/or no syntax, that is newer than PHP 5.2 (and MySQL 4.1).

Tschö, Auge

--
further development of mlf1

Tags:
2.4, bug

Avatar

Report about an error with the notation of an object

by Milo ⌂, Friday, February 17, 2017, 17:52 (183 days ago) @ Auge

Hi,

I guess this is due to PHP version. It does not work on 5.2 and 5.3. It
works well on PHP 5.4+

Hmm, seems to be right, e.g. php create object without class or on php.net.

Should we change it like this (I don't have PHP <5.6)?

$release = (object) array(
'title'   => (string)$title[0],
'content' => (string)$content[0],
'version' => (string)$lastVersion,
'uri'     => $baseURI . (string)$releaseURI[0]->href
);

/Micha

--
Surveyor-Software: Geodetic Network Adjustment & Deformation-Analysis and Transformation

Avatar

Report about an error with the notation of an object

by Auge ⌂ @, Friday, February 17, 2017, 19:51 (183 days ago) @ Milo

Hi,

Should we change it like this (I don't have PHP <5.6)?

$release = (object) array(
'title'   => (string)$title[0],
'content' => (string)$content[0],
'version' => (string)$lastVersion,
'uri'     => $baseURI . (string)$releaseURI[0]->href
);

I think, this would be a good idea.

Tschö, Auge

--
further development of mlf1

Avatar

Report about an error with the notation of an object

by Milo ⌂, Friday, February 17, 2017, 20:37 (183 days ago) @ Auge

Hello Auge,

I think, this would be a good idea.

Done by #196

/Micha

--
Surveyor-Software: Geodetic Network Adjustment & Deformation-Analysis and Transformation

RSS Feed of thread
powered by my little forum