0

Is it possible to do something like this:

Class::function('some_text') = 'aaaaa';

And get this 'aaaaa' string inside the Class::function() ?

2
  • 4
    I don't think so. why not just simply pass 'aaaaa' as a parameter? Commented Oct 10, 2012 at 10:55
  • I just thought it could be a bit more clear in my case. Such as: Session::set('key') = 'value'; Instead of: Session::set('key', 'value'); Commented Oct 10, 2012 at 10:57

4 Answers 4

1

With your case it seems like you're searching for a solution like this?

Session::Set(array("key" => "value"));

class Session {
    public static function Set($kvp) {
        foreach ($kvp as $key => $value) {
            echo $key . " is " . $value . "<br />";
        }
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Uhh, minusing my post for looking for the best solution :P Thanks for your answers, I can see the best solution is passing two parameters.
@user1615069 FYI, I didn't downvote you, but the person that did downvote you probably did it because of the lack of info from your side as to what exactly it was that you wanted to do (it wasn't very clear).
1

Yes it is by doing this:

MyClass::func('some_text', 'aaaaa');

E.g.

class MyClass {
    public static function func($text, $aaa) {
        ...
    }
}

Alternatively (and much worse then the previous IMHO):

global $foo;
$foo = 'bar';

class Baz {
    public static function bong() {
        global $foo;
        ...
    }
}

Comments

1

That syntax is not available in PHP.

In Perl, this type of function would be called an LVALUE function.

Comments

0

you can return a reference and change the value of it.

class MyClass {

  private static $variable;

  public static function &func($random_param) {
    return self::$variable;
  }
}

call it like this

$reference = &MyClass::func('asd');
$reference = "15";

echo MyClass::func('asdasd'); // "15"

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.