SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    { } for no reason?

    Hi,

    It is rather dumb question, I am checking someone's code, there are opening and closing {} with out any if statmnent, Is there a reason I don't understand thats thye are there or just by mistake?, they do not give any syntax error though



    Code:
                              $this->stage = 1;
    		//Affiliate id changes
    		{
    			if($this->lead->affiliate_id == 1167)
    			{
    				$this->lead->affiliate_id = 1657;
    				$_REQUEST['lead']['affiliate_id'] = 1657;
    			}
    		}

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's valid syntax, but it makes no real difference. It can be used to show that a certain piece of code is a unit, but this is purely semantical - eg. for making the code easier to read. It may also be that there used to be a control statement of some kind, which have now been removed.
    In C (Which PHP is modelled over), a block has it's own variable scope, but PHP doesn't inherit this feature.
    Here's an example, showing block scope in C :
    http://icecube.wisc.edu/~dglo/c_class/scope.html
    Code:
    int a;
    
    void f(void)
    {
    	float a;	/* different from global `a' */
    	float b;
    
    	a = 0.0;	/* sets `a' declared in this block to 0.0 */
    			/* global `a' is untouched */
    	{
    		int a;	/* new `a' variable */
    
    		a = 2;	/* outer `a' is still set to 0.0 */
    	}
    	b = a;		/* sets `b' to 0.0 */
    }
    
    /* global `a' is untouched by anything done in f() */


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •