473,396 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Curly braces without pre-keyword do not cause parse error.

Markus
6,050 Expert 4TB
I came across this today while thinking how I could put the Boyer-Moore string search algorithm into PHP.

Wouldn't you expect the following to give you a parse error?

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. echo "Ok ...";
  4.  
  5. {
  6.     echo "I'm inside rogue curly braces!";
  7. }
  8. ?>
  9.  
Strangely, it outputs both echo calls.

Is this built-in behavior for something? Does this parse correctly for you? Am I loosing it?
May 23 '09 #1
3 1580
prabirchoudhury
162 100+
you are right.. php execute first anything inside the curly braces . it would be php build in behavior that only work on curly braces.
May 24 '09 #2
Atli
5,058 Expert 4TB
Yea, I stumbled onto that to a while back.

Thought it was kind of odd at first, but it can be kind of useful to.
It can help organize long procedural scripts. Especially if your editor has the sense to allow code folding on these independent blocks.

I mean, considering that these sort of blocks can even contain functions and classes, this can be very helpful
May 24 '09 #3
Markus
6,050 Expert 4TB
@Atli
Exactly what I was thinking.

I still want to know whether this is a bug or purposeful; I'll ask on php.net.
May 24 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: deko | last post by:
Do I need to use curly brackets in PHP if .. else statements? other constructs? Does it matter? What are Best Practices? Why? thanks in advance... This seems to work WITHOUT curly brackets:...
8
by: Ken in Melbourne Australia | last post by:
If I use the curly bracket syntax (referred to as the complex syntax) within a string, how do I get to call a function within it? The php manual says that the first (or previous) character for...
0
by: Dustin D. | last post by:
Let's say I have a text file with the following: food { fruits { apples oranges pears } dairy { ice_cream {
6
by: STF | last post by:
While reading the C++ tutorial in this page: http://www.cplusplus.com/doc/tutorial/tut2-2.html I'm astonished to learn that we could omit curly brackets in function declaration for single...
4
by: JavaGeekRoyR | last post by:
Hello all.. In the VS.Net IDE, is there a way to auto-format your code (such that the curly braces for code blocks automatically align, code is automatically indented to proper levels etc)? If...
5
by: krbyxtrm | last post by:
Hi is there a way to 'manage' function execution using macros? #define MY_CALL_MACRO(MacroName) { g_MacroStack.push_back(MacroName); <some code here...>} such that when i use the...
5
by: TJ | last post by:
I'd like to know how the preprocessor treats curly braces, as compared to how it treats parentheses. What happens if I pass this: { a_function( arg1, arg2, arg3 ) } as an argument to a...
3
by: Grande News | last post by:
Hi, I've got some PHP code that looks like this $cura= ord($data{$pnum*2}); $curb = ord($data{$pnum*2+1}); Notice the curly braces -- does using them make any difference, or will square...
4
by: Nick S | last post by:
I've just been trying to de-construct the jQuery tooltop plugin in an attempt to better my javascript coding and I've come across a question google can't help me with. What is the deal with...
2
by: xskltn | last post by:
int main() { { const std::string name = "a string"; std::cout << name << std::endl; { const std::string name = "another string"; std::cout << name << std::endl;}} return 0; } My question is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.