-6
<?php
class a
{
    protected $c=10;

}
class b extends a{

    echo a::$c;

    }
    //$obj = new b();

?>

Here I am trying to print the parent class variable in the child class. can you tell me how to make use of the parent class variables in child class in PHP5?

3
  • Have you tried anything? Please show your code. Commented Jun 3, 2015 at 13:24
  • Not entirely sure what you are asking, but did you look at the official manual? Commented Jun 3, 2015 at 13:25
  • Have a look over http://php.net/manual/en/language.oop5.visibility.php Commented Jun 3, 2015 at 13:26

1 Answer 1

1
class parent {
    protected $field;
}
class child extends parent {
  public function test() {
    return $this->field;
  }
}

Doc: http://php.net/manual/en/language.oop5.visibility.php

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.