News for hackers. Stuff that matters.
Re:Things you should know about PHP 7 by franciscop on Thursday March 26, 2015 @10:19AM (#9269759)
Seeing this:

> function add( ... ): float {}

I think a much better choice would have been:

> float function add( ... ) {}

Or just:

> float add( ... ) {}

Since that's how it's done in other languages and people would feel at home with it.

Re:Things you should know about PHP 7 by juriansluiman on Thursday March 26, 2015 @10:28AM (#9269827)
The idea is that the old php syntax "function foo ()" remains unchanged [1] so developers can keep searching for "function foo". Removing "function" as keyword is a different topic and is discussed in a separate php thread [2].

The thing you mention ("float function add(){}") keeps the option to search for "function add", but I am unsure why this is not taken into account in this proposal.

Anyhow, I am pretty happy this finally made it to the php language.

[1] https://wiki.php.net/rfc/return_types#position_of_type_decla...

[2] http://marc.info/?t=141235344900003&r=1&w=2

Re:Things you should know about PHP 7 by steveklabnik on Thursday March 26, 2015 @12:33PM (#9270907)
Having 'function foo' be grep-able is _wonderful_. My last language, Ruby, isn't very grep-able, but my current one, Rust, uses 'fn foo', and being able to just use 'git grep' to find things is _wonderful_.
Re:Things you should know about PHP 7 by greiskul on Thursday March 26, 2015 @10:31AM (#9269850)
Go also does types different from C, and they have a nice page explaining the reasoning of their syntax here: http://blog.golang.org/gos-declaration-syntax
Re:Things you should know about PHP 7 by Danack on Thursday March 26, 2015 @08:50PM (#9274183)
> function add( ... ): float {}

Which if you read it out, it sounds entirely natural "This is a function called foo, which takes some params, and returns a float". Most of the other variants don't read as naturally.

> Since that's how it's done in other languages and people would feel at home with it.

PHP doesn't need to copy the mistakes of other languages. It's got plenty of its own mistakes.

Re:Things you should know about PHP 7 by Spoom on Thursday March 26, 2015 @10:24AM (#9269802)
I thought that was rather odd as well. Are there many languages using this form of return type specifier?
Re:Things you should know about PHP 7 by dtech on Thursday March 26, 2015 @10:40AM (#9269907)
It's fairly common in languages that determine (return) types themselves, e.g. Haskell, Scala and F# all use this syntax. Most languages that use a C-style syntax put (return) types in front.

It makes very little sense for PHP. A function definition now even has both styles:

`function foo(argtype arg) : rettype` instead of `function rettype foo(argtype arg)` or `function foo(arg : argtype) : rettype`.

Re:Things you should know about PHP 7 by TazeTSchnitzel on Thursday March 26, 2015 @10:45AM (#9269945)
Hack, ActionScript and TypeScript put the type after. Hack is most likely where this syntax came from.
Re:Things you should know about PHP 7 by Drakim on Thursday March 26, 2015 @10:21AM (#9269776)
Haxe uses the first syntax, as does AS3. So it's not like "other languages" are universally opposed to this order.
Re:Things you should know about PHP 7 by tne on Thursday March 26, 2015 @10:31AM (#9269849)
AFAICT both Haxe and AS3 consistently put types on the right, including argument declarations. Other languages consistently put it on the left. Most languages make a choice like that; PHP mixes things up a bit.

But then, it wouldn't be PHP if it was too consistent ;).

Re:Things you should know about PHP 7 by TazeTSchnitzel on Thursday March 26, 2015 @10:54AM (#9270028)
To be fair, it's not the same as an argument type. The type of `foo()` isn't int, it's function. You're not specifying the type of the thing itself, merely the type of what it returns. Though this seems to have been lost on the creators of C. ;)
Re:Things you should know about PHP 7 by aikah on Thursday March 26, 2015 @10:58AM (#9270067)
sure but AS3, Go Haxe and others ARE consistant

    function foo(a:int,b:string):bool{}
in PHP this will be

    function foo(int a,string b):bool{}
Re:Things you should know about PHP 7 by notacoward on Thursday March 26, 2015 @12:11PM (#9270685)
Putting the type first for parameters and last for return values seems like exactly the same kind of inconsistency that has already earned PHP plenty of criticism. Personally I kind of like the Pascal style, I use the C style all day every day, but mixed style seems like the worst option available.
Re:Things you should know about PHP 7 by allan_s on Thursday March 26, 2015 @10:28AM (#9269826)
Rust also has this syntax if I remember correctly, for parsing reason
Re:Things you should know about PHP 7 by pilsetnieks on Thursday March 26, 2015 @10:32AM (#9269853)
Go also has a similar syntax (except the colon)
Re:Things you should know about PHP 7 by amyjess on Thursday March 26, 2015 @10:57AM (#9270058)
This is actually how it's done in Pascal.

Everything old is new again.

Re:Things you should know about PHP 7 by rokhayakebe on Thursday March 26, 2015 @10:23AM (#9269791)
Swift?