1

I have problem to access the private and public variable within the static function. I know to access the static variable to access the static function.

Sample Example:

class Student{ public $name = "Rajkumar"; private $mark = 10; static $result = "Pass"; static function Display(){ echo(self::$result); //here how to access $name and $mark } } 

Is this possible or not.

1
  • 1
    you can only access static variables from static functions Commented Dec 24, 2012 at 7:15

1 Answer 1

3

You have to mark the properties as static as well. You can't access non-static properties from a static function, even if those properties have hardcoded values (like your example).

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.