PHP code example of khalyomede / prototype

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

    

khalyomede / prototype example snippets


class Tableau extends Prototype {
  protected $items;

  public function __construct($items = []) {
    $this->items = $items;
  }
}

$tableau = new Tableau(['php', 'python', 'nodejs']);

$tableau->prototype('all', function() {
  return $this->items;
});

$languages = $tableau->all();

namespace Me;

use Khalyomede\Prototype;

class Tableau extends Prototype {
  protected $items;

  public function __construct($items = []) {
    $this->items = $items;
  }

  public function all() {
    return $this->items;
  }
}

use Me\Tableau;

$languages = ['php' => '7.2', 'python' => '3.6', 'nodejs' => '8.6'];

$tableau = new Tableau($languages);

$tableau->prototype('className', function() {
  return 'Tableau';
});

echo $tableau->className();

use Me\Tableau;

$languages = ['php' => '7.2', 'python' => '3.6', 'nodejs' => '8.6'];

$tableau = new Tableau($languages);

$tableau->prototype('first', function() {
  return $this->items[key($this->items)];
});

$version = $tableau->first();

echo $version;

use Me\Tableau;

$languages = ['php' => '7.2', 'python' => '3.6', 'nodejs' => '8.6'];

$tableau = new Tableau($languages);

$tableau->prototype('find', function($key) {
  return isset($this->items[$key]) ? $this->items[$key] : null;
});

$python_version = $tableau->find('python');

echo $python_version;

public static function prototypes(): array

public function prototype(string $name, callable $function): Prototype