Skip to content

Instantly share code, notes, and snippets.

@gamunax
Last active November 21, 2018 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gamunax/2418015e1631bcc6a32854db91fe2f6b to your computer and use it in GitHub Desktop.
Save gamunax/2418015e1631bcc6a32854db91fe2f6b to your computer and use it in GitHub Desktop.
Clase protegida php
<?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