Last Updated: February 25, 2016
· ravinsharma7

Experimentation with data-flow structures with PHP

Lately, I have been experiment and delving into data-flow techniques in PHP. I sometimes get a bit woozy with OOB, my brain has kept on bugging me on some other way to express code and computation using classes. I wanted a way to express and change my code logic in a seemless manner. This is rough structure which I came up with.

POC: Abstraction of program sequence and data states.

interface iStateHolder{}
interface iNode{}
class StateHolder implements iStateHolder{
  public function StateHolder($state){
      foreach($state as $key => $state){
        $this->$key = $state;
        $this->state = $state;

class Node implements iNode{

  private $creation_time, $state_object, $_return;

  public function Node(iStateHolder &$state = null){    
      $this->creation_time = time();  
      $this->state_object = $state;

  public function foo1(){
     // do stuff
     $this->_return = $return_data = "foo1 return data";
     return $this;

  public function foo2(){
    // do stuff 
    $this->_return = $return_data = "foo2 return data";
    return $this;
  public function foo3(){
    // do stuff 
    $this->_return = $return_data = "foo3 return data";
    return $this;
  public function link(iNode $adjacent_node){
    $adjacent_node->_return = $this->_return; 

  public function state_object(){
    return $this->state_object;

  public function return_data(){
    return $this->_return;

  public function creation_time(){
    return $this->creation_time();

$node1 = new Node(new StateHolder(
    'ip' => "",
    'host_name' => 'ravin',
    'sample' => 'watever'
$node2 = new Node();

// program sequence is abstracted, and pass data to node2 via link method

// holds the state object passed  by reference
// node2 has the return data of foo2()