1

If needed, parameters can be passed to a class via it's constructor.

class Test {

  public function __construct($echo) {
    echo $echo;
  }

}

$test = new Test('hello'); // Echos "hello"

Is there any way of passing parameters to the __destruct?

class Test {

  public function __construct($echo) {
    echo $echo;
  }

  public function __destruct($string) { // Is this possible?
    // Do something with this string
  }

}

2 Answers 2

2

No, Destructors have only one signature

void __destruct ( void )

Manual

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I couldn't seem to find that anywhere.
1

It's not possible. But you can use a instance field like this:

class Test {
  var $value;
  public function __construct($echo) {
    this->value = $echo;
  }
  public function __destruct() {
    echo $this->value;
  }
}

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.