-
-
Save gamunax/9ff06cfc7945dc0fe8c59eb985455b26 to your computer and use it in GitHub Desktop.
Clase privada 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 | |
{ | |
private $nombre = 'Jose Perez'; // variable de tipo privado | |
private $totaldinero = 150000; | |
public function getNombreAbuelo() //funcion publica | |
{ | |
return $this->nombre; //la variable de tipo privado solo es usado en la clase | |
} | |
private function getDinero() | |
{ | |
return $this->totaldinero; | |
} | |
} | |
$objAbuelo = new Abuelo(); | |
echo $objAbuelo->nombre; //error por ser privado la variable | |
echo $objAbuelo->getNombreAbuelo(); //se muestra Jose Perez | |
echo $objAbuelo->getDinero();//mostrara el error Call to private method Abuelo::getDinero(), ya que la función es privada y solo puede ser usado dentro su clase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment