PHP code example of thenlabs / class-builder

1. Go to this page and download the library: Download thenlabs/class-builder 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/ */

    

thenlabs / class-builder example snippets




use ThenLabs\ClassBuilder\ClassBuilder;

$personClass = new ClassBuilder('Person');
$personClass->setNamespace('ThenLabs\Demo');

$personClass->addProperty('name')->setAccess('protected');

$personClass->addMethod('__construct', function (string $name) {
    $this->name = $name;
});

$personClass->addMethod('getName', function (): string {
    return $this->name;
});

$personClass->install();

$andy = new Person('Andy');

$andy->getName() === 'Andy';            // true
$andy instanceof \ThenLabs\Demo\Person; // true