-
-
Save gamunax/2418015e1631bcc6a32854db91fe2f6b to your computer and use it in GitHub Desktop.
Clase protegida php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Abuelo | |
{ | |
protected $nombre = 'Jose Perez'; // variable de tipo privado | |
} | |
class Padre extends Abuelo | |
{ | |
function getNombreAbuelo() | |
{ | |
echo $this->nombre; | |
} | |
} | |
$objetoPadre = new Padre(); | |
echo $objetoPadre->getNombreAbuelo(); //muestra Jose Perez, porque la clase Padre tiene la harencia de Abuelo, sin herencia nos mostraria error | |
$objAbuelo = new Abuelo(); | |
echo $objAbuelo->nombre; //Cannot access protected property Abuelo::$nombre | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment