Req #77815 [Opn->Sus]: New feature request - Introduce 'using' keyword/feature similar to C#
| From: | requinix@php.net | Date: | Thu, 28 Mar 2019 17:20:47 +0000 |
| Subject: | Req #77815 [Opn->Sus]: New feature request - Introduce 'using' keyword/feature similar to C# | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220238@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77815&edit=1
ID: 77815
Updated by: requinix@php.net
Reported by: piotr dot ziarek at yahoo dot co dot uk
Summary: New feature request - Introduce 'using'
keyword/feature similar to C#
-Status: Open
+Status: Suspended
Type: Feature/Change Request
-Package: PHP Language Specification
+Package: Scripting Engine problem
PHP Version: 7.3.4RC1
Block user comment: N
Private report: N
New Comment:
For language changes like this, please use the RFC process. https://wiki.php.net/rfc/howto
Previous Comments:
------------------------------------------------------------------------
[2019-03-28 14:11:48] piotr dot ziarek at yahoo dot co dot uk
Description:
------------
Currently there is no way in PHP to control the scope/lifetime of a variable. In C# there is an
interface called IDisposable which allows for explicit disposal by using a 'using'
keyword.
I'm proposing a explicit destructor to be called in PHP in a similar manner.
'using' should behave like an 'if' statement - it should not require curly
brackets for a single command inside in it, multiple commands should be wrapped in curly brackets.
Test script:
---------------
<?
using($t=new Div) //no semicolon since this should be like an 'if'
echo 'inside';
echo 'outside';
//
//
//---class Div---------------
class Div{
function __construct(){
echo '<div>';
}
function __destruct(){
echo '</div>';
}
}
?>
Expected result:
----------------
if 'using' was implemented, the example code above should output:
"<div>inside</div>outside"
Actual result:
--------------
'using' currently will display an error:
PHP Parse error: syntax error, unexpected 'echo' (T_ECHO)
//or depending on a semicolon(just to give you you a real failure reason)
PHP Fatal error: Uncaught Error: Call to undefined function using()
without 'using' it will say "<div>insideoutside</div>" - last
</div> will be displayed at the very end of script probably when PHP disposes all variables.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77815&edit=1