<?php
class main{
  public $bob="my name bob";
  private $lee="my surname lee";
  protected $david="my caste";
       function output(){
  $output=$this->lee;
   echo $output;
}
} class second extends main{ } $obj= new second; $obj->output();

?>

the output is 'my surname lee'. how ? i am confused with private and protected.please let me understand the working of it.and what is polymorphism in php any tutorial link or example.

有帮助吗?

解决方案

polymorphism in php is well explained here.

In one word: Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface.

For your question: However the variable

$lee

is private, the function

function output()

is public and can be accessed outside.

And this page have more specific sinariao in the php programming language.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top