Location: PHPKode > scripts > Java and C# compatible scalar type hinting > php_5.2_example.php
<?php


ini_set("display_errors", true);
error_reporting(E_ALL);
date_default_timezone_set('Europe/Warsaw');

require('./typehint.php');

$x = new TypeHint();
echo "<pre>";

function testString(string $a) {
	var_dump($a);
}

function testBoolean(bool $a) {
	var_dump($a);
}

function testInt(int $a) {
	var_dump($a);
}

class test
{
	public static function staticTester(string $a) {
		var_dump($a);
	}
	
	public function objectTester(bool $a) {
		var_dump($a);
	}
}

$tester = new test();
$tester->objectTester(true);
test::staticTester("a");

// OK
testString("a");

// ERROR: Catchable fatal error: Argument 1 passed to testString() must be an instance of string, integer given, called in C:\lotos\public_html\example.php on line 30 and defined in C:\lotos\public_html\example.php on line 13
testString(12);

/*

// OK
testBool(true);

// ERROR
testBool(false);

*/

/*

// OK
testInt(12);

// ERROR
testInt("a");

*/
Return current item: Java and C# compatible scalar type hinting