PHP code example of jcstrandburg / extension-methods
1. Go to this page and download the library: Download jcstrandburg/extension-methods 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/ */
jcstrandburg / extension-methods example snippets
class Person
{
use trait Extensible;
public function __construct(string $firstname, string $lastname) {
$this->firstname = $firstname;
$this->lastname = $lastname;
}
public function getFirstname() {
return $this->firstname;
}
public function getLastname() {
return $this->lastname;
}
private $firstname;
private $lastname;
}
Person::extend('getFullname', function (Person $x) {
return $x->getFirstname() . ' ' . $x->getLastname();
});
$bob = new Person('Bob', 'Roberts');
$bob->getFullname() == 'Bob Roberts';