|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77815 New feature request - Introduce 'using' keyword/feature similar to C#
Submitted: 2019-03-28 14:11 UTC Modified: 2019-03-28 17:20 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: piotr dot ziarek at yahoo dot co dot uk Assigned:
Status: Suspended Package: Scripting Engine problem
PHP Version: 7.3.4RC1 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: piotr dot ziarek at yahoo dot co dot uk
New email:
PHP Version: OS:


 [2019-03-28 14:11 UTC] piotr dot ziarek at yahoo dot co dot uk
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:

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-28 17:20 UTC]
-Status: Open +Status: Suspended -Package: PHP Language Specification +Package: Scripting Engine problem
 [2019-03-28 17:20 UTC]
For language changes like this, please use the RFC process.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Jul 29 18:01:23 2021 UTC