<?php
// php 4 redundancy

print("hello world!\n"); //this is my comment?> <?print("this will be seen!");?><?
try {
    echo 1;
    return;
} catch(Exception $e) {
    echo 2;
} catch(Exception $e) {
   echo 22;
}
echo 3;
?>


<?
try {
        echo 1;
} catch(Exception $e) {
        echo 2;
        return;
}
echo 3;
?>



<?
function test() 
{ 
        $fields['company'] = ''; 
        $fields['contact'] = ''; 
        $fields['email'] = ''; 
         
        return $fields; 
}
$x = test();
var_dump($x);
?>

<?php

function get_UID() {
global $User;
if (get_class($User)=='jwuser') {
return ($User->uid);
} else {
return 0; 
}
}
?>


<? 
function GetHelpline() {
/**
* Returns the helpline number set
*/

if ($this->GetCountry() == "uk") return
$this->texts["text"]["helpline-en"];
if ($this->GetCountry() == "ire") return
$this->texts["text"]["helpline-ire"];
if ($this->GetCountry() == "nz") return
$this->texts["text"]["helpline-nz"];
else return $this->texts["text"]["helpline-ot"];
}
?>


<?
function fromUpload($data) {
	$img = new CImage;
 	$img->imageFilename = ObjectState::createID();
 	$img->imageMimeType = 'image/jpeg';
 	$img->uploadedFile = $data['tmp name'];
 	return $img;
 }
?>


<?php

    // Returns an indexed array of associative arrays (including keys 'key',
    // 'name', 'desc', 'authorname', 'authorcontact', bool 'package_loaded',
    // array 'modules', array 'loaded_modules') of all currently registered
    // packages
    function EnumeratePackages()
    {
        // The array that's holding our output
        $out = array();

        // Grab a Modules object
        $m = &Modules::singleton();

        // Go through our registry
        foreach ($this->_registry as $package)
        {
            // Create the associative array for this element
            $element = array(
                'key' => $package->key,
                'name' => $package->name,
                'desc' => $package->desc,
                'authorname' => $package->authorname,
                'authorcontact' => $package->authorcontact,
                'package_loaded' =>
                    in_array($this->_loaded_packages, $package->key),
                'modules' => $m->EnumModulesByKey($package->key),
                'modules_loaded' => $m->EnumLoadedModulesByKey($package->key)
                );

            // Add element to output array
            $out[$package->key] = $element;
        }

        // Return output array
        return $out;
    }

?>


<?php
$db = ("John");
	  	    
function display(){
	global $db;
	var_dump($db);
}

display();
?>


<?
function adds($var1, $var2){
	$i= $var1+$var2;
	if($i>10) 
		return $i;
	else
		return(adds($i,$i));
}
?>

<?php
if(print("hello")){
	print("\ngood\n");
}

?><?php
/******************************************/
/******currently doesn't work well!!!******/
/******************************************/

$a=array(1,3,"a",7,0,"b",9);

if($a[0]){
	print("that's good\n");
}

if($a[4]){
	print("that's bad\n");
}

 if(($a=array(1,2))){
 print("bye");
 }


?><?php

print("hello world!\n"); //this is my comment?> <?print("this will be seen!");?><?php

print("hello world!\n"); //this is my comment?> <?print("this will be seen!");?><?php
if(print("hello")){
	print("\ngood\n");
}

?><?php
class Foo{
	var $x;
	function hell(){}
}

if($a=new Foo()){
	print("bye");
}
?> <?php

function hello($x,$y){
	print("$x $y");
}

hello(1,&$a);
?><?php
$x=1;
$y=0;

if($x==1)
if($y==0)
print("hello");
else print("else");
?><?php
define(foo,1);

$a=foo;
print("$a");


define('boo',11);
$b=boo;
print("\n$b");
?><?php
define("foo");
$a=foo;
print("$a");
?><?php
$foo =2;
$i=5;
while($i)
{
	if($i<=0) break;
	while($i)
	{
		if($i<=0) break;
		while($i)
		{
			if($i<=0) break;
			while($i)
			{
				if($i<=0) break;
				break $foo;
			}
			print("level1\n");
			--$i;
		}
		print("level2\n");
		--$i;
	}
	print("level3\n");
	--$i;
}
print("level 4 - end\n");
?><?php
while(1){
	while(1){
		while(1){
			while(1){
				while(1){
					while(1){
						break 1000;
					}
				}
			}
		}
	}
}

print("the end");
?>
	<?php

function hello_world($x,$y,$z)
{
	$z=$y=$x=0;
	$y=$x;
	$y=$z;
	$z=$y;
	$obj=new myClass();
	$obj->myFunc(1,8);
}

class myClass{
	var $a;
	function myFunc($m,$n)
	{
		print("$m is the result");
	}
}

hello_world(1,2,3);
?><?

function hello($x){
	print("\nhello: $x\n");
}

function globalHello($y){
	global $myVar;
	print("\ngHello: $y\n");
}

hello(2);
globalHello(4);

?>
<?php

function useMe()
{
	if($x<10)
	print("the value is: $x\n");
}

useMe(9);
?>
<?php
while($a<7)
{
	print("ok");
	$a++;
}
?>
	<?php
while($a<7)
{
	print("ok");
	$a++;
}
?>
	<?php
class NumberClass{
	function twoer()
	{
		$x=2;
		return $x;
	}
	
	function oner()
	{
		$x=3;
		$x++;
		return 1;
	}
}

$a=new NumberClass();
$res=$a->oner();
print("$res");
$res=$a->twoer();
print("$res");
?><?php
function changeMe(&$x)
{
	$x=3;
	print("changed to 3!\n");
}

function DONTchangeMe(&$x)
{
	print("i am what i am which is $x\n");
}

$varvar=99;
DONTchangeMe($varvar);
changeMe($varvar);
?><?php
function changeMe(&$x)
{
	$x=3;
	print("changed to 3!\n");
}

function DONTchangeMe(&$x)
{
	print("i am what i am which is $x\n");
}

$varvar=99;
DONTchangeMe($varvar);
changeMe($varvar);
?><?php
function MyReTUrn($x)
{
	if($x>5)
	return 1;
	elseif($x>0)
	return 2;
	else
	return;
}

$res=MyReTUrn(7);
print("i got $res\n");
?><?php
function noResponse($x)
{
	if($x>0) {};
}

$x=noResponse(-9);
print("$x");
?><?php
function noResponse($x)
{
	if($x>0) {};
}

$x=noResponse(-9);
print("$x");
?>?><?php
$path='c:\Documents and Settings\dubi\Desktop\test\1.php';
include($path);
include_once($path);
require($path);
require_once($path);
?>
<?php

$a=array(1,3,"a",7,0,"b",9);

if($a[0]){
	print("that's good\n");
}

if($a[4]){
	print("that's bad\n");
}

if($a=array(1,5,"a",7)){
	print("that's a mistake!\n");\
}

$c=0;	
if($c=array(1,5,"a",7)){
	print("that's a mistake!\n");
}

?><?
$variable = 1;
for($i=0;$i<10;$i++) {
    $variable += $i;
    if($variale > 10) { // typo here!
        echo $i;
    }
}
?><?
if (time() %2 == 0){
  $boolean = true;
}
else{
  $boolean = false;
}

	
if($boolean){
  print ("Zugi\n");
  exit ;
}
else{
 print ("I zugi\n");
 //if ($boolean==0)
 exit;
}
?>

abc 

<?php
if(1)
{
	print("hello");
}
else
{
	print("bye");
}

// php 5 examples
interface INamed
{
   public function getName();
}
interface ISon
{
   public function getFather();
}
interface IFather
{
   public function getSons();
}

abstract class Named implements INamed
{
   protected $name;
   public function __construct($name)
   {
       $this->name = $name;
   }
   public function __destruct()
   {}
   public function getName()
   {
       return $this->name;
   }
}
abstract class Son implements ISon
{
   protected $father;
   public function getFather()
   {
       return $this->father;
   }
   public function __construct(IFather $father = null)
   {
       $this->father = $father;
   }
   public function __destruct()
   {}
}
abstract class Father implements IFather
{
   protected $sons = array();
   public function getSons()
   {
       return $this->sons;
   }
   public function __construct($sons = array())
   {
       $this->sons = $sons;
   }
   public function __destruct()
   {}
}

class Man implements INamed, ISon, IFather
{
   public function __construct($name, IFather $father = null, $sons = array())
   {
       // note: these are just __construct() calls - not real class initializations
       Named::__construct($name);
       Son::__construct($father);
       Father::__construct($sons);
   }
   public function __destruct()
   {
       Named::__destruct();
       Son::__destruct();
       Father::__destruct();
   }
   public function getFather()
   {
       return Son::getFather();
   }
   public function getSons()
   {
       return Father::getSons();
   }
   public function getName()
   {
       return Named::getName();
   }
}

$siarhej = new Man('Siaroh', new Man('Adas'), array(new Man('Seva')));

var_dump($siarhej->getName());
var_dump($siarhej->getFather()->getName());
$siarhejSons = $siarhej->getSons();
var_dump($siarhejSons[0]->getName());

   
class Employee {
   
	private $employeeid;
    private $tiecolor;

    function setEmployeeID($employeeid) {
       $this->employeeid = $employeeid;
    }
    function getEmployeeID() {
       return $this->employeeid;
    }
    function setTiecolor($tiecolor) {
       $this->tiecolor = $tiecolor;
    }
    function getTiecolor() {
       return $this->tiecolor;
    }

    function __clone() {
       $this->tiecolor = "blue";
    }
}

   $emp1 = new Employee();
   $emp1->setEmployeeID("1111");   
   $emp2 = clone $emp1;
   $emp2->setEmployeeID("2222");

   echo "emp employeeID: ".$emp1->getEmployeeID()."<br />";
   echo "emp employeeID: ".$emp2->getEmployeeID()."<br />";
   echo "emp tiecolor: ".$emp2->getTiecolor()."<br />";
   
class SelfExample
{
   // Hold an instance of the class
   private static $instance;
   
   // A private constructor; prevents direct creation of object
   private function __construct() 
   {
       echo 'I am constructed';
   }

   // The singleton method
   public static function singleton() 
   {
       if (!isset(self::$instance)) {
           $c = __CLASS__;
           self::$instance = new $c;
       }

       return self::$instance;
   }
   
   // Example method
   public function bark()
   {
       echo 'Woof!';
   }

   // Prevent users to clone the instance
   public function __clone()
   {
       trigger_error('Clone is not allowed.', E_USER_ERROR);
   }

}   

class BaseClass {
   public function test() {
       echo "BaseClass::test() called\n";
   }
   
   final public function moreTesting() {
       echo "BaseClass::moreTesting() called\n";
   }
}

class PageGenerator{
    private $output='';
    private $title;
    public function __construct($title='Default Page'){
        $this->title=$title;
    }
    public function doHeader(){
        $this->output='<html><head><title>'.$this->title.'</title></head><body>';
    }
    public function addHTMLElement($htmlElement){
        if(!$htmlElement instanceof HTMLElement){
            throw new Exception('Invalid (X)HTML element');
        }
        $this->output.=$htmlElement->getHTML();
    }
    public function doFooter(){
        $this->output.='</body></html>';
    }
    public function fetchHTML(){
        return $this->output;
    }
}


$page = new PageGenerator();
$page->__construct("title");
$page->doHeader();
try {
	$page->addHTMLElement("simple test");
} catch (Exception $error){
	// Do something
}
$page->doFooter();
echo $page->fetchHTML();


__halt_compiler();
?> 