Exemplo n.º 1
0
<?php

// This is an example of using setters and getter methods to set and access
// variables that are inside the class.
class SetterGetterExample
{
    private $a = 1;
    public function set_a($value)
    {
        $this->a = $value;
    }
    public function get_a()
    {
        return $this->a;
    }
}
$ex = new SetterGetterExample();
// restricted: echo $ex->a . "<br>";
echo $ex->get_a();
echo "<br>";
$ex->set_a(15);
echo "<br>";
echo $ex->get_a();
echo "<br>";
Exemplo n.º 2
0
<?php

include_once 'html5req.php';
?>
    <div class="row">
        <div class="small-12 medium-6 large-6 columns">
            <h1 class="text-center">Access Modifiers: 2</h1>
<?php 
class SetterGetterExample
{
    private $a = 1;
    public function get_a()
    {
        return $this->a;
    }
    public function set_a($value)
    {
        $this->a = $value;
    }
}
$example = new SetterGetterExample();
// restricted : echo $example->a . '<br>';
echo $example->get_a() . '<br>';
$example->set_a(15);
echo $example->get_a() . '<br>';
?>
		</div>
	</div>
Exemplo n.º 3
0
<?php

//Setters and Getters
class SetterGetterExample
{
    private $a = 1;
    public function get_a()
    {
        return $this->a;
    }
    public function set_a($value)
    {
        $this->a = $value;
    }
}
$example = new SetterGetterExample();
// restricted: echo $example->a."<br />";
echo $example->get_a() . "<br />";
$example->set_a(15);
echo $example->get_a() . "<br />";