From:
Operating system:
PHP version: Irrelevant
Package: Variables related
Bug Type: Feature/Change Request
Bug description:Tolerant and Strict Variables and functions
Description:
------------
These are suggestions for PHP 6.0.
A tolerant variable, unlike a scalar, has an assigned type. If a value is
placed in a tolerant variable of the wrong type it silently casts it to the
correct type. It would require a new language keyword, "tolerant".
tolerant string $a = 'hello';
$a = false;
echo $a // echos the string value of false, ''
A strict variable behaves much the same but triggers an error (or throws
exception) rather than silently recasting. It requires a new keyword
"strict"
strict int $a = 5;
$a = false; // exception thrown.
The purpose of these var types is to build a better bridge between
undata-typed
programming used by beginning coders and strict data-typed programming used
by
veterans without forcing the former camp to adjust - PHP's strength is ease
of
learning.
Tolerant functions apply the recasting to their incoming arguments
according to
the datatypes hinted for the objects - if the value isn't of the
appropriate
object a new object ob the type hinted is created receiving that value as
an
argument.
Strict functions throw errors but can also overload sharing names with each
other so long as no two strict functions try to have both the same name and
argument types. So
strict function foo ( int $a ) {}
strict function foo ( string $a ) {}
strict function foo ( MyClass $a ) {}
would be possible.
--
Edit bug report at http://bugs.php.net/bug.php?id=53159&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=53159&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=53159&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=53159&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=53159&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=53159&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=53159&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=53159&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=53159&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=53159&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=53159&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=53159&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=53159&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=53159&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=53159&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53159&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53159&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=53159&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=53159&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=53159&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=53159&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=53159&r=mysqlcfg