0

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
3
  • getSomething() { /* Do stuff here */ } Commented Mar 19, 2016 at 16:10
  • 1
    that requires a class to run with, seeing "public". Commented Mar 19, 2016 at 16:10
  • I know that guys, but a external library have this sintaxis. See the edit Commented Mar 19, 2016 at 16:12

2 Answers 2

4

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() {}

ceejayoz
181k42 gold badges311 silver badges382 bronze badges
answered Mar 19, 2016 at 17:05
Sign up to request clarification or add additional context in comments.

1 Comment

And if it's an external library, you'll need to use an older PHP5-compatible version of it.
-1

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.