![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
comp.lang.php archiveRe: Strict types
From: Umberto Salsi <salsi@icosaedro.italia>
Date: Mon May 01 2006 - 03:07:52 CEST
"Treefrog" <info@designstein.co.uk> wrote:
> For a while now I've been wishing PHP had (at least the option to
Starting from the same thought, I realized that a scripting language has
Faced with the perspective to switch to another strong-typed language
Problem: no PHP formal validators seem to be available. That's way
unused constants/variables/functions/classes/properties/methods (for
type mismatch in items usage (you can't add a string to a number without
type mismatch in function arguments (you can't pass a string to a function
all the properties of a class must be declared; their type given by the
This sample of code should give an idea. The comments summaryze the complains
<?php
class Example {
public function __construct(/*. string .*/ $s, $i=0)
public function getString()
$obj = new Example("hello");
$obj->aString = ""; # <-- ERROR: accessing private property
$obj->gggg = 999; # <-- ERROR: no property gggg in class Example
$obj2 = new Example(123); # <-- ERROR: expected arg of type string
$num = 3;
$num = $obj; # <-- ERROR: type mismatch in assignment
if( $num === 0 ) { $num = 1; } # ok
$fp = fopen("data1.txt", "r");
$fp = fopen("data2.txt", "r") || die("xxx"); # ERROR: invalid expr
?>
# notice: the property `anInt' used only inside its class, you should make it `private'
Regards,
|