0

Assuming the following class

class test {

public $x = 2;

public testFunction() {

//...

}

}

Is there any way I can access $x from within testFunction()?

Thanks! :)

1 Answer 1

0

Absolutely, simply using $this->x

You may wish to brush up on PHP's OOP principles.

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

2 Comments

Can I do it even if $x = new OtherClass()? Because I seem to get an error there...
If $x is a property of test, but is an instance of another class this is still perfectly valid. Perhaps consider posting another question with a paste of your new code and the error message you receive.

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.