RE: [PHP-DEV] FW: Functionality request/proposal

From: Date: Tue, 15 Jan 2013 02:53:57 +0000
Subject: RE: [PHP-DEV] FW: Functionality request/proposal
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Ok, let me try again.




Yeah, I know the C++ standard don't allow that semi-colon there... but both GCC and CLang
won't complain if you add it there, and GCC accepts it even in Java. I've seem lots of
code where people put it there, and I always get a little frustrated when using PHP because I'm
used on adding it (without even noticing), and my code keeps failing because of that.

Wouldn't hurt to make the parser simply ignore it. =P






Know, about the multiple returns...
Ruby and Lua let you return multiple values... why won't PHP allow you?
Usually it's best to return an array, I totally agree, but I was working on a Lisp-like parser
for PHP yesterday and it would really help me for two expressions to be returned from a single
function, since I'm using tail recursion and on a few cases I needed to add two values to an
array.

You guys will tell me to use something like flatten(), probably RecursiveArrayIterator or stuff,
but... for future implementations, that multiple return would help. =P





Better?




Date: Mon, 14 Jan 2013 14:48:08 +0100
Subject: Re: [PHP-DEV] FW: Functionality request/proposal
From: [email protected]
To: [email protected]
CC: [email protected]; [email protected]




2013/1/14 Johannes Schlüter <[email protected]>

On Mon, 2013-01-14 at 04:10 +0000, Paulo Henrique Torrens wrote:

> Hi,

>

> I'm currently interested in two features I'd like to see in PHP; how do I proceed to
> request/propose them? I'd be glad to help implementing them as well, if necessary.

>

>

> One of them is really simple, but would be helpful to people with different coding styles

>

> class Test {

>   public function blabla() {

>     // ...

>   } // < the interpreter fails if there

>     //   is a semicolon here, although

>     //   some c++ programmers may be used

>     //   to add it



That one is wrong in C++, too. Unless you're confusing function

declarition with function definitions.



class CPPClass {

    void some_declaration();

    void some_definition_of_an_inline_function() {

       return;

    } // No ; here

}



> };



Well, people should be aware of the language they are using ...



> And the other one would be multiple return values

>

> function multi() {

>   return 10, 20;



Use

     return [10, 20];

which exists and returns an array. This is clear and quite easy to read.





> };

> function sum($a, $b) {

>   return $a + $b;

> };

>

> echo sum(multi()); // echoes 30



This becomes confusing when reading.


echo array_sum(multi()); // :)
 




johannes





--

PHP Internals - PHP Runtime Development Mailing List

To unsubscribe, visit: http://www.php.net/unsub.php





-- 
github.com/KingCrunch 

 		 	   		  


Thread (7 messages)

« previous php.internals (#64964) next »