Self vs static in php

class A {
    public static function className(){
        echo __CLASS__;
    }

    public static function test(){
        self::className();
    }
}

class B extends A{
    public static function className(){
        echo __CLASS__;
    }
}

B::test();

This will print

A

In the other hand with static:: It has the expected behaviour

class A {
    public static function className(){
        echo __CLASS__;
    }

    public static function test(){
        static::className();
    }
}

class B extends A{
    public static function className(){
        echo __CLASS__;
    }
}


B::test();

This will print

B

Tower of Hanoi in PHP

<?php


function moveTower($height, $fromTower, $toTower, $viaTower)
{
	echo $height  . "<br>";
	if ($height >= 1)
	{	
		moveTower($height-1, $fromTower, $viaTower, $toTower);
		moveDisk($fromTower, $toTower);
		moveTower($height-1, $viaTower, $toTower,  $fromTower);
	}
	else
	{
		//moveDisk($fromTower, $toTower);
	}
	
}

function moveDisk($a, $b)
{
	echo "Moving disk from" . $a . " to " . $b . "<br>";
}


moveTower(3, 'A','B','C');
exit; 

PHP Implementation of Singly Linked List

<?php

class listNode {

    function __construct($data) {
        $this->data = $data;
        $this->next = null;
    }

}

class linkedList {

    function __construct() {

        $this->head = NULL;
    }

    function insert($data) {
        $node = new listNode($data);
        $node->next = $this->head;
        $this->head = $node;
        //if ()
    }

}

class reverse {

    function reversing($obj) {

        $current = $obj->head;
        print_r($current);
        $previous = null;
        $a = 0;
        while ($current != null) {
            echo $a++;
            $head = $current->next;
            $current->next = $previous;
            $previous = $current;
            $current = $head;
        }
        $obj1 = $previous;
        print_r($obj1);
    }

}

$myLinkedList = new linkedList();
$myLinkedList->insert(1);
$myLinkedList->insert(2);
$myLinkedList->insert(3);
$myLinkedList->insert(4);
$myLinkedList->insert(5);
$myLinkedList->insert(6);
//$myLinkedList->insertBegin(4);
echo "Reverse<br>";
$myReverse = new reverse();
$myReverse->reversing($myLinkedList);