|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-03-28 17:20 UTC] requinix@php.net
-Status: Open
+Status: Suspended
-Package: PHP Language Specification
+Package: Scripting Engine problem
[2019-03-28 17:20 UTC] requinix@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 16:00:01 2025 UTC |
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.