PHP Classes

JavaScript Like Prototypes: Implement class prototypes similar to JavaScript

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 198 This week: 1All time: 8,496 This week: 560Up
Version License PHP version Categories
falcraftprototypes 1.0MIT/X Consortium ...5.3PHP 5, Data types, Language
Description 

Author

This class implement class prototypes similar to JavaScript.

It can set classes functions as function closures and variables to given values.

New prototype classes can inherit the prototype definitions of base classes.

Innovation Award
PHP Programming Innovation award nominee
December 2015
Number 8
JavaScript implements a different object model based on prototypes for functions and variables that are made available to all objects that use the same prototypes.

This package implements a solution that can work in PHP like JavaScript prototypes.

Prototype functions use dynamically assigned PHP function closures. It also supports prototype inheriting for creating new object prototypes.

Manuel Lemos
Picture of Asher Wolfstein
  Performance   Level  
Name: Asher Wolfstein <contact>
Classes: 15 packages by
Country: United States United States
Age: 40
All time rank: 1122164 in United States United States
Week rank: 51 Up6 in United States United States Up
Innovation award
Innovation award
Nominee: 5x

Example

<?php

require_once('../../Patterns/Prototype.php');

use
Falcraft\Patterns;

echo
"Falcraft\\Patterns\\Prototype.php Test\n";
echo
"------------------------------------\n\n";

echo
"Instantiating Prototype -> ";

$success = true;

$prototype1 = null;

try {
   
$prototype1 = new Patterns\Prototype();
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

echo
"Retrieve Identity and Register -> ";

$success = true;

$prototype1Identity = '';

try {
   
$prototype1Identity = $prototype1->getIdentity();
   
$prototype1->register();
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
} else {
    echo
"Failure...\n\n";
}

echo
"Define Properties On Base Prototype -> ";

$success = true;

try {
   
$prototype1->testFunction = function () {echo "Inside Test Function\n";};
   
$prototype1->testMemberVariable = "Test Member Variable\n";
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

echo
"Get Prototype Using Base as Parent -> ";

$success = true;

$prototype2 = null;

try {
   
$prototype2 = $prototype1->from();
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

echo
"Prototype Inherits Properties -> \n";

$success = true;

try {
    echo
' ';
   
$prototype2->testFunction();
    echo
' ';
    echo
$prototype2->testMemberVariable;
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
} else {
    echo
"Failure...\n\n";
}

echo
"Prototype 2 'Redefines' testFunction -> \n";

$success = true;

try {
   
$prototype2->testFunction = function(){echo "Inside Test Function 2\n";};
    echo
' ';
   
$prototype2->testFunction();
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
} else {
    echo
"Failure...\n\n";
}

echo
"Instantiate Prototype 3 from Prototype 2,\n";
echo
"Define new Prototype 1 Function,\n";
echo
"Call new function from prototype 3 => ";

$success = true;

try {
   
$prototype3 = new Patterns\Prototype();
   
$prototype3->__parent = $prototype2;
   
$prototype1->newTestFunction = function(){echo"Inside New Test Function\n";};
   
$prototype3->newTestFunction();
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
} else {
    echo
"Failure...\n\n";
}


  Files folder image Files  
File Role Description
Files folder imageFalcraft (1 file, 2 directories)

  Files folder image Files  /  Falcraft  
File Role Description
Files folder imageexamples (1 directory)
Files folder imagePatterns (1 file, 1 directory)
  Accessible without login Plain text file falcraftLoad.php Aux. Loader Abstraction

  Files folder image Files  /  Falcraft  /  examples  
File Role Description
Files folder imagePatterns (1 file)

  Files folder image Files  /  Falcraft  /  examples  /  Patterns  
File Role Description
  Accessible without login Plain text file Prototype.php Example Example Script

  Files folder image Files  /  Falcraft  /  Patterns  
File Role Description
Files folder imageException (2 files)
  Plain text file Prototype.php Class Main Class

  Files folder image Files  /  Falcraft  /  Patterns  /  Exception  
File Role Description
  Plain text file ExceptionInterface.php Class Exception Interface
  Plain text file RuntimeException.php Class Local Exception Class

Downloadfalcraftprototypes-2015-12-06.zip 6KB
Downloadfalcraftprototypes-2015-12-06.tar.gz
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
PHP Configuration Trait Download .zip .tar.gz Configuration of Class Required
Abstract Data Types Download .zip .tar.gz You Can Use Map As Registry Required
 Version Control Unique User Downloads Download Rankings  
 0%
Total:198
This week:1
All time:8,496
This week:560Up