|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53159 Tolerant and Strict Variables and functions
Submitted: 2010-10-25 22:22 UTC Modified: 2017-09-12 10:33 UTC
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: dmgx dot michael at gmail dot com Assigned:
Status: Suspended Package: Variables related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-10-25 22:22 UTC] dmgx dot michael at gmail dot com
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 

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 

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-27 02:45 UTC] uramihsayibok at gmail dot com

If you have a new idea, submit an RFC. Less likely to be shrugged off.
 [2017-09-12 10:33 UTC]
-Status: Open +Status: Suspended
 [2017-09-12 10:33 UTC]
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 ( as an RFC. Please read
the guide about creating RFCs here:
<>. If you haven't had experience
with writing RFCs before, it is advised to seek guidance on the
Internals list (<>) 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.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Oct 22 20:03:44 2021 UTC