PHP-SugarNewsWikiDocsBugsForumFilesSource LoginRegister
HomeForumsDevelopmentFunction call syntax
Function call syntax
Development
Sean Middleditch Jul 27th, 2008 at 2:17pm
As mentioned in the delimiters topic, I've found that some things in Sugar just don't work out so well after a lot of real-world experience. The (new) function call syntax has proven itself more irritating than helpful.

I added mandatory commas to function calls to work around a syntax ambiguity. Namely, the following call:

func $a [1,2,3]

Sugar would try to parse that as an array index on $a, and then throw a syntax error on the commas. Because Sugar uses a very simple hand-written recursive-descent parser, it really wasn't feasible to avoid that.

After using Sugar a lot, I found that unnamed parameters just really aren't that useful. Designers tend to prefer the more markup-like named parameters, they don't like the commas, and the one or two places where the named parameters were considered ugly aren't ugly enough to justify all the pain.

So... all function calls in Sugar now require named parameters. Yup.

Method calls still work and act like PHP method calls. That is, the arguments must be in parenthesis, separated with commas, and cannot be named. Function calls, however, cannot have commas, must be named, and the parameter list can never be put in parenthesis.

If you want to call a function inside of an expression, parenthesis are not required, but I do recommend them. That, these two lines are equivalent:

func1 foo=func2 bar='string'
func1 foo=(func2 bar='string')

I highly recommend just using the latter syntax. I may make that required in a future release after a little more real-world experience is gained with the new required syntax.

Sorry for the inconvenience to anyone who has a lot of existing template code. Yes, it's a pain to convert it all. I'll buy you a beer in apology if we ever meet.

Reply to Topic
or Login