Req #53159 [Opn->Sus]: Tolerant and Strict Variables and functions
| From: | cmb@php.net | Date: | Tue, 12 Sep 2017 10:33:36 +0000 |
| Subject: | Req #53159 [Opn->Sus]: Tolerant and Strict Variables and functions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-211087@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53159&edit=1
ID: 53159
Updated by: cmb@php.net
Reported by: dmgx dot michael at gmail dot com
Summary: Tolerant and Strict Variables and functions
-Status: Open
+Status: Suspended
Type: Feature/Change Request
Package: Variables related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Thank you for your interest in PHP and for submitting a feature
request. Please be aware that due to the magnitude of change this
request requires, it would be necessary to discuss it on PHP
Internals list (internals@lists.php.net) as an RFC. Please read
the guide about creating RFCs here:
<https://wiki.php.net/rfc/howto>. If you
haven't had experience
with writing RFCs before, it is advised to seek guidance on the
Internals list (<http://php.net/mailing-lists.php>) and/or solicit
help from one of the experienced developers.
Please do not consider this comment as a negative view on the
merits of your proposal â every proposal which requires changes of
certain magnitude, even the very successful and widely supported
ones, must be done through the RFC process. This helps make the
process predictable, transparent and accessible to all developers.
Previous Comments:
------------------------------------------------------------------------
[2010-10-27 02:45:29] uramihsayibok at gmail dot com
See http://wiki.php.net/rfc/typechecking
If you have a new idea, submit an RFC. Less likely to be shrugged off.
------------------------------------------------------------------------
[2010-10-25 22:22:47] dmgx dot michael at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=53159&edit=1