Created
November 7, 2016 19:31
-
-
Save gorkamu/73d6db5a544334fa54b13910be3e69a8 to your computer and use it in GitHub Desktop.
Ejemplo de propiedades y métodos
This file contains hidden or 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 Television | |
{ | |
public $tipo = 'Television plana'; | |
protected $pulgadas = '47 pulgadas'; | |
private $marca = 'Samsung'; | |
public static $codigoDeModelo = 'DASX29348X-1290'; | |
public function imprimeValores() { | |
echo $this->tipo.PHP_EOL; | |
echo $this->pulgadas.PHP_EOL; | |
echo $this->marca.PHP_EOL; | |
} | |
public function dameSuCodigoDeModelo() { | |
return self::$codigoDeModelo; | |
} | |
} | |
// Instanciamos la clase utilizando el constructor por defecto | |
$television = new Television(); | |
echo $television->tipo; // Imprimirá por pantalla el valor 'Television plana' | |
echo $television->pulgadas; // Dará un error | |
echo $television->marca; // Dará un error | |
echo $television->imprimeValores(); // Imprimirá los valores definidos en las propiedades | |
echo Television::$codigoDeModelo; // Imprime la variable estática | |
echo $television->dameSuCodigoDeModelo(); // Imprime la variable estática |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment