FluidTYPO3 / fluidcontent

TYPO3 extension Fluidcontent: Fluid Content Element Engine
71 stars 64 forks source link

Issue with ?? operator in ConfigurationService.php #395

Closed davidjgreen closed 7 years ago

davidjgreen commented 7 years ago

Hi, Possible bug to report and possible fix too. I'm running php7.1.2 but keep getting this error message

Parse error: syntax error, unexpected '?' in /path-to-my-typo3/typo3conf/ext/fluidcontent/Classes/Service/ConfigurationService.php on line 312

This corresponds to the line " ) ?? $tabId; "

Don't know if its my compiled php that's the problem, but it doesn't like the null coalescing operator ?? bit. By rearranging the code block to remove the ?? operator, the error message goes away.

So, lines 309-312

$wizardTabs[$tabId]['title'] = $this->translateLabel(
        'fluidcontent.newContentWizard.group.' . $group,
        ExtensionNamingUtility::getExtensionKey($extensionKey)
        ) ?? $tabId;

becomes

$tempTabTitle = $this->translateLabel('fluidcontent.newContentWizard.group.' . 
    $group, ExtensionNamingUtility::getExtensionKey($extensionKey));

if( $tempTabTitle != null  ){
    $wizardTabs[$tabId]['title'] = $tempTabTitle;
}else{
    $wizardTabs[$tabId]['title'] = $tabId;
}

Hope this is useful. Best wishes David

cedricziel commented 7 years ago

Are you 100% sure that you're running a PHP version supporting the nco? This seems very, very odd to me, since parsing errors should pop up in our testing environments.

Can you, as a small test, check if you could use the following:

$foo = null;
$bar = $foo ?? 'bar';

Another reason could be that you're using different PHP versions for web and cli since you didn't tell us where this error popped up.

davidjgreen commented 7 years ago

You're quite right - my inexperience. Your test code passed, so it can't be that the nco operator isn't supported. But still its odd that this particular error should crop up and resolve when reorganised to remove it.

The error occurred when starting a new plugin with pretty much nothing in it yet. Just two basic almost empty controllers.

NamelessCoder commented 7 years ago

Is it possible that perhaps your HTTPD is using a 5.x version of PHP and your CLI uses 7.0.x or vice versa? It is indeed a bit suspect that the test code works but other null coalesce operators fail ;)

davidjgreen commented 7 years ago

Hi, Yes you are right - they are different. The CLI uses php 5.4.5 but HTTPD is using 7.1.2. The server setup is all controlled by a Plesk automatic system, so I would have no idea how to get them on to the same version. But yes, it does sound like my server is the issue.

cedricziel commented 7 years ago

Thank you for your investigation!

Well that's a pitty. - But good to know that it's not the extension causing trouble.

davidjgreen commented 7 years ago

I'm also glad its not the extension, as that would be a hassle for lots of other people, not just me. I can work around the ?? issue. Thanks for your time in helping me get to the bottom of this. And thanks for creating the extension in the first place. :-) Best wishes David