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

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.

Comments

Your Answer

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.