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

2013-01-15 Thread Steve Clay

On 1/14/13 9:53 PM, Paulo Henrique Torrens wrote:

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


Pay more attention and/or use an IDE that has templates and shows parse errors.

Enforcing syntax is a good thing; Javascript's auto semicolon insertion has led to a 
staggering amount of wasted energy in bug fixing, understanding the feature, arguments 
about it, and altering code between the two styles. It was a terrible, terrible idea.


Steve Clay
--
http://www.mrclay.org/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



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

2013-01-14 Thread Paulo Henrique Torrens
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: krebs@gmail.com
To: johan...@schlueters.de
CC: paulo_torr...@hotmail.com; internals@lists.php.net




2013/1/14 Johannes Schlüter 

On Mon, 2013-01-14 at 04:10 +, 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 

  

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

2013-01-14 Thread Sebastian Krebs
2013/1/14 Johannes Schlüter 

> On Mon, 2013-01-14 at 04:10 +, 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


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

2013-01-14 Thread Johannes Schlüter
On Mon, 2013-01-14 at 04:10 +, 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.

johannes


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



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

2013-01-14 Thread Ángel González
On 14/01/13 05:10, 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.
You should propose it here and then create a rfc about it in the php
wiki, which is finally voted.


> 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
> };
I don't think this is a good addition.


> And the other one would be multiple return values
>
> function multi() {
>   return 10, 20;
> };
> function sum($a, $b) {
>   return $a + $b;
> };
>
> echo sum(multi()); // echoes 30
>
> $x, $y = multi();
>
> echo $y; // echoes 20

Are you aware that you could use arrays here?

function multi() {
  return array(10, 20);
}

list($x, $y) = multi();

echo $y; // echoes 20


For passing to a new function it is a bit uglier but still easy:
echo call_user_func_array('sum', multi()); // echoes 30


Functions could be changed to receive the members of an array as the
different arguments, but that would conflict with passing an array as
the first argument. It would be also harder to read the code, too.


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



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

2013-01-14 Thread Stas Malyshev
Hi!

> function multi() {
>   return 10, 20;
> };

This can be done with:

function multi() {
return [10, 20];
}

list($x, $y) = multi();

However, sum() won't work this way:

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

But can work this way:

call_user_func_array("sum", multi());


-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php