C style blocks

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

C style blocks

Post by anjanesh »

Is there any way to have the C style blocks ?

Code: Select all

<?php
 {
 	$a=5;
 	echo $a;
 }
echo $a;
?>
The output of this
55
instead I want it to be
5
Notice: Undefined variable: a in xxx.php on line xx

I want this to free some memory after usage in a block.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use unset on all variables created in the block.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Yes. Thats one method but its manual and for many variables its extra work. C style blocks make it so much easier.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yeah.. too bad they don't exist in PHP. boo hoo. :cry: :? (outside of functions)
Post Reply