PHP code example of tasso / prototype

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

    

tasso / prototype example snippets



use TassoEvan\Prototype\Prototype;

$obj = new Prototype();
$obj->a = function($x) {
	return $x + 2;
};

$obj->a(2); // returns 4



use TassoEvan\Prototype\Prototype;

$obj = new Prototype(function($x) {
     return $x + 2;
});

$obj(2); // returns 4



use TassoEvan\Prototype\Prototype;
use TassoEvan\Prototype\NormalProperty;

$obj = new Prototype();
$obj->a = new NormalProperty('My value');

echo $obj->a; // outputs 'My value'



use TassoEvan\Prototype\Prototype;

$obj = new Prototype();
$obj->a = Prototype::normal('My value');

echo $obj->a; // outputs 'My value'



use TassoEvan\Prototype\Prototype;

$obj = new Prototype();
$obj->a = 'My value';

echo $obj->a; // outputs 'My value'



use TassoEvan\Prototype\Prototype;

$obj = new Prototype();
$obj->a = 'My value';

echo $obj->a; // outputs 'My value'

$obj->a = 'My new value';

echo $obj->a; // outputs 'My new value'



use TassoEvan\Prototype\Prototype;

$obj = new Prototype();
$obj->a = Prototype::readOnly('My value'); // non-strict

echo $obj->a; // outputs 'My value'
$obj->a = 'My new value';
echo $obj->a; // outputs 'My value'

$obj->b = Prototype::readOnly('My value', true); // strict

echo $obj->b; // outputs 'My value'
$obj->b = 'My new value'; // a `UnexpectedValueException`



use TassoEvan\Prototype\Prototype;

$obj = new Prototype();

$obj->db = Prototype::lazy(function() use($myDSNString) {
    // connected only when used
    return new PDO($myDSNString);
});

$obj->db->exec('UPDATE poke_registry SET pokes = pokes+1'); // connects to database and performs a query



use TassoEvan\Prototype\Prototype;

$obj = new Prototype();

$obj->a = Prototype::dynamic(function() {
        return "foo";
    },
    function($value) {
        echo "Do you want to set {$value} to this property?";
    });

echo $obj->a;           // outputs "foo"
$obj->a = 3;            // outputs "Do you want to set 3 to this property?"