[solved] brace in a php contruction???

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
robbedoes
Forum Members
Forum Members
Posts: 75
Joined: Wed Aug 20, 2008 2:08 pm
Location: Nijmegen, the Netherlands

[solved] brace in a php contruction???

Post by robbedoes »

While creating a module I had a look at the News module. In News/action.defaultadmin.php I found this code snippet:

if( $this->CheckPermission( 'Modify Templates' ) ) {
   echo $this->StartTab('summary_template', $params);
   {
     echo ''.$this->Lang('title_available_templates').'';
     $this->_AdminCreateTemplateList($id,$returnid,
     'summary',
     'default_summary_template_contents',
     'summary_template',
     'current_summary_template',
     $this->Lang('title_summary_template'));
   }
   echo $this->EndTab();

My question is what this brace is doing:

echo $this->StartTab('summary_template', $params);
   {

Thanks,

Rob
Last edited by Anonymous on Sat Jul 25, 2009 9:07 pm, edited 1 time in total.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm
Location: Comox Valley, BC

Re: brace in a php contruction???

Post by Nullig »

I think what he's saying is that there's no "conditional" statement to warrant the "{".

Nullig
robbedoes
Forum Members
Forum Members
Posts: 75
Joined: Wed Aug 20, 2008 2:08 pm
Location: Nijmegen, the Netherlands

Re: brace in a php contruction???

Post by robbedoes »

Nullig wrote: I think what he's saying is that there's no "conditional" statement to warrant the "{".

Nullig
Indeed :-) No If, no function, just an opening brace, some code and then a closing brace.
I’ve had a look at the PHP documentation but there is nothing about this kind of use.

Rob
Last edited by robbedoes on Mon Jul 20, 2009 7:57 am, edited 1 time in total.
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: brace in a php contruction???

Post by Dee »

AFAIK the curly braces are (besides control structures) mainly used for complex syntax in strings.

I use it a lot when I'm using object methods in sql queries, for example:

Code: Select all

$sql = "SELECT * FROM {$config->GetTable()} WHERE some_field = {$someobject->GetSomeValue()}";
(to prevent having to do something like:)

Code: Select all

$sql = "SELECT * FROM " . $config->GetTable() . " WHERE some_field = " . $someobject->GetSomeValue()";
(or:)

Code: Select all

$table = $config->GetTable();
$value = $someobject->GetSomeValue();
$sql = "SELECT * FROM $table WHERE some_field = $value;
When they're used around a some lines of code like in this case I think it's just to show that the lines/statements form a "code block"/statement group (for readability purposes).
statements can be grouped into a statement-group by encapsulating a group of statements with curly braces
Regards,
D
Last edited by Anonymous on Mon Jul 20, 2009 12:03 pm, edited 1 time in total.
robbedoes
Forum Members
Forum Members
Posts: 75
Joined: Wed Aug 20, 2008 2:08 pm
Location: Nijmegen, the Netherlands

Re: brace in a php contruction???

Post by robbedoes »

I am coding PHP for years but never saw this handy construction.
Thank you Dee for the kind explanation.

Best regards,

Rob
Post Reply

Return to “Developers Discussion”