LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-03-2011, 06:17 AM   #1
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
Question PHP, {}, and ";" after them


Hello. In C++ (AFAIK) after "if {...}" you also should add ";". But after this statement in PHP you don't have to (might look like negligence, which is so like PHP). But what is a better practice in PHP?

Code:
if (true)
{
  echo 'True';
};

echo 'END';
Is this coding style better than

Code:
if (true)
{
  echo 'True';
}

echo 'END';
?

Last edited by Mr. Alex; 11-03-2011 at 06:19 AM.
 
Old 11-03-2011, 08:12 AM   #2
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
I'd go with whatever's valid syntax, being as it looks clear enough without the ;. In fact, I tend to comment something like } // end if describe condition in many languages.

If you don't like this PHP syntax quirk, you might hate Python
 
Old 11-03-2011, 09:59 AM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by Mr. Alex View Post
Hello. In C++ (AFAIK) after "if {...}" you also should add ";".
No, you don't have to do this and I've never seen anyone do this. You do have to add ";" after the closing brace of a declaration (eg struct or enum): "struct { ... };".
 
Old 11-03-2011, 12:11 PM   #4
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ntubski View Post
You do have to add ";" after the closing brace of a declaration (eg struct or enum): "struct { ... };".
You mean OOP?

Here's C++ example:
Code:
#ifndef __ADDRBAR_H
#define __ADDRBAR_H

#ifdef CONFIG_ADDRESSBAR

#include "yinputline.h"

class AddressBar: public YInputLine {
public:
    AddressBar(YWindow *parent = 0);
    virtual ~AddressBar();

    virtual bool handleKey(const XKeyEvent &key);

    void showNow();
    void hideNow();
};

#endif

#endif
 
Old 11-03-2011, 12:41 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by Mr. Alex View Post
You mean OOP?
Not specifically, but a semicolon is required after a class declaration as well.
 
1 members found this post helpful.
  


Reply

Tags
php



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Event Announcment: PHP | OSI Days 2010 - Asia's Largest PHP Conference" anandan1982 Linux - News 0 06-08-2010 09:24 PM
weird PHP compile issue- module shows in "php -m" but not in phpinfo call hbbtstar Linux - Software 1 08-28-2009 03:14 PM
Urgent PHP problem with "undefined function: domxml_open_mem()"! Recomplie php? Oskare100 Linux - Server 0 12-27-2006 12:28 PM
PHP / VideoLAN / Fedora Core Question - how can I get the PHP "exec" function to work gtrawoger Linux - Software 3 12-21-2005 06:51 AM
php ide with "break" and "trace" Kayaker Programming 3 04-25-2003 02:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration