|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-10-27 02:45 UTC] uramihsayibok at gmail dot com
[2017-09-12 10:33 UTC] cmb@php.net
-Status: Open
+Status: Suspended
[2017-09-12 10:33 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 03:00:01 2025 UTC |
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.