PHP code example of hrn4n / magic

1. Go to this page and download the library: Download hrn4n/magic library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hrn4n / magic example snippets


 
class Person extends Access\Magic
{
  protected $name;
}



$me = new Person;

$me->setName("Hernan");

$me->get("name"); # returns "Hernan"
$me->getName(); # also returns "Hernan"


 
class Person extends Access\Magic
{
  protected $name;
  
  public function onNameSet($name) {
    # convert name to uppercase before setting 
    return strtoupper($name);
  }
}

 
$me = new Person;
$me->set("name", "hernan"); # alternative way of setting properties

$me->getName(); # returns "HERNAN"