Does anyone know this PHP function syntax and how it works? It's not working with PHP 5.5
public function getProxiesTargetDir() : string
{
return $this->proxiesTargetDir ?: $this->proxiesTargetDir = sys_get_temp_dir();
}
Jimmy T.
4,1993 gold badges25 silver badges41 bronze badges
asked Mar 19, 2016 at 16:08
Carlos Gomez
791 gold badge3 silver badges10 bronze badges
2 Answers 2
You are using typed returns public function getProxiesTargetDir() : string which only exists starting from PHP 7.
For previous versions just remove : string> public function getProxiesTargetDir() {}
Sign up to request clarification or add additional context in comments.
1 Comment
ceejayoz
And if it's an external library, you'll need to use an older PHP5-compatible version of it.
You are using the shorthand if/else syntax of PHP here, but let's use the long way:
public function getProxiesTargetDir()
{
if( $this->proxiesTargetDir == false ){
return ( $this->proxiesTargetDir = sys_get_temp_dir() );
}
else{
return $this->proxiesTargetDir;
}
}
If have also deleted the :string, because it can make errors and it is not really necessary here.
answered Mar 19, 2016 at 17:03
KIMB-technologies
8796 silver badges14 bronze badges
Comments
lang-php
getSomething() { /* Do stuff here */ }