Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP

2008-06-19 Thread troels knak-nielsen
On Thu, Jun 19, 2008 at 8:44 AM, Andi Gutmans <[EMAIL PROTECTED]> wrote:
>> >> - In PHP 5, object storage is resources done right. I don't think
>> >> we should be using the resource infrastructure for this
>> >> implementation and would prefer to use the object one. It's better.
>> >> I suggest to take a look at it.
>>
>> Hmm, seems like a good idea. If nobody objects in the next few days,
>> I'll rewrite my patch to use objects instead of resources. What class
>> name do you suggest?
>
> Great. I think Closure is probably a good name.
> [Btw, if we want to get fancy we could even have a __toString() method on 
> those which would print out information about the Closure. But this is not a 
> must, just something which eventually could be nice for debugging purposes...]
>

Using objects, instead of resources is an excellent idea. Would it be
possible to introduce a general __invoke (Or whatever name is more
fitting) magic-method, so that whichever object implements that
method, is callable with call_user_func (and directly through
variable-function-syntax). Eg.:
class Foo {
  function __invoke($thing) {
echo "Foo: " . $thing;
  }
}

$foo = new Foo();
$foo("bar"); // > echoes "Foo: bar"

I'm not sure how this would play together with lexical scope?

--
troels

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



Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP

2008-06-19 Thread Dmitry Stogov
Hi Christian,

I took a look into your patch and found it too difficult.
So I implemented another patch (attached) which is based on your ideas.

>From user's level of view it does exactly the same except for "lexical"
variables definition. I don't use any new reserver word because every
new reserved word is going to break some user code. I use the special
syntax for lambda function definition instead, which looks much clear
for me. The following code creates a lambda function with arguments $x,
$y and lexical variables $a, $b, $c.

$a = function($x, $y | $a, $b $c) {};

The patch shouldn't affect opcode caches and other extensions as it
doesn't change any structures. It uses the op_array->static_variables
for lexical variables.

The patch also fixes several small issues and adds some missing
functionality which didn't allow preg_replace_callback() (and may be
others) to work with lambda functions. Now the following example works fine.

foo($x[0].':'.$s);
};
  }
}

$x = new X;
$x = $x->bar("bye\n");
$s = 'abc';
preg_replace_callback('/[abc]/', $x, $s);
?>

It prints:

a:1:bye
b:2:1:bye
c:3:2:1:bye

Of course the patch doesn't break any existent tests.

Please review.

Thanks. Dmitry.

Christian Seiler wrote:
> Hi,
> 
> As a followup to the discussion in January, I'd like post a revised 
> patch to
> this list that implements closures and anonymous functions in PHP.
> 
> INTRODUCTION
> 
> 
> Closures and lambda functions can make programming much easier in 
> several ways:
> 
>  1. Lambda functions allow the quick definition of throw-away functions
> that are not used elsewhere. Imaging for example a piece of code that
> needs to call preg_replace_callback(). Currently, there are three
> possibilities to acchieve this:
> 
>  a. Define the callback function elsewhere. This distributes code that
> belongs together throughout the file and decreases readability.
> 
>  b. Define the callback function in-place (but with a name). In that 
> case
> one has to use function_exists() to make sure the function is only
> defined once. Example code:
> 
>   function replace_spaces ($text) {
>   if (!function_exists ('replace_spaces_helper')) {
> function replace_spaces_helper ($matches) {
>   return str_replace ($matches[1], ' ', ' ').' ';
> }
>   }
>   return preg_replace_callback ('/( +) /', 
> 'replace_spaces_helper',
> $text);
> }
>  ?>
> 
> Here, the additional if() around the function definition makes the
> source code difficult to read.
> 
>  c. Use the present create_function() in order to create a function at
> runtime. This approach has several disadvantages: First of all, 
> syntax
> highlighting does not work because a string is passed to the 
> function.
> It also compiles the function at run time and not at compile 
> time so
> opcode caches can't cache the function.
> 
>  2. Closures provide a very useful tool in order to make lambda 
> functions even
> more useful. Just imagine you want to replace 'hello' through 
> 'goodbye' in
> all elements of an array. PHP provides the array_map() function which
> accepts a callback. If you don't wan't to hard-code 'hello' and 
> 'goodbye'
> into your sourcecode, you have only four choices:
> 
>  a. Use create_function(). But then you may only pass literal values
> (strings, integers, floats) into the function, objects at best as
> clones (if var_export() allows for it) and resources not at all. 
> And
> you have to worry about escaping everything correctly. 
> Especially when
> handling user input this can lead to all sorts of security issues.
> 
>  b. Write a function that uses global variables. This is ugly,
> non-reentrant and bad style.
> 
>  c. Create an entire class, instantiate it and pass the member function
> as a callback. This is perhaps the cleanest solution for this 
> problem
> with current PHP but just think about it: Creating an entire 
> class for
> this extremely simple purpose and nothing else seems overkill.
> 
>  d. Don't use array_map() but simply do it manually (foreach). In this
> simple case it may not be that much of an issue (because one simply
> wants to iterate over an array) but there are cases where doing
> something manually that a function with a callback as parameter 
> does
> for you is quite tedious.
> 
> [Yes, I know that str_replace also accepts arrays as a third 
> parameter so
> this example may be a bit useless. But imagine you want to do a more
> complex operation than simple search and replace.]
> 
> PROPOSED PATCH
> --
> 
> I now propose a patch that implements compile-time lambda functions and
> clos

Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Steph Fox



I'd prefer a run-tests.php option that sets the timeout limit in seconds.


Nice idea, but I'm not sure it's achievable under CLI.

- Steph


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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Steph Fox


Hi Travis,

All it does is adds another option, -x, to run-tests.php. This sets  an 
environmental variable which can then be checked for in the  SKIPIF 
section of very slow-running tests.


How do you specify that "test A is slow"?  Is there a certain skipif 
message you include, or...?


Yep. The two that bug me most are actually labelled 'slow test', so having a 
skipif condition for those wouldn't be too obscure. Note that it's only 
intended for when you're repeatedly running the same group of tests...


I like Chris's idea better, but can't see a way to implement it. There's 
probably something really obvious I'm missing, let me know if.


- Steph 



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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Steph Fox


Hey Stas,


+$environment['EXEMPT_SLOW_TESTS'] = 1;


Maybe "SKIP_SLOW_TESTS"? If it's checked in skip section... :)
Otherwise - good idea!


You can tell I'm reading my mail backwards today...

I used 'EXEMPT' because the option is 'x' and I wanted it to be easy to 
remember. 's' wasn't available.


- Steph


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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Nuno Lopes

I'd prefer a run-tests.php option that sets the timeout limit in seconds.


Nice idea, but I'm not sure it's achievable under CLI.


Yes, it is. Check the system_with_timeout() function in the run-tests.php 
script.
There you've the timeout hardcoded ('$leak_check ? 300 : 60'). You would 
just need to make it configurable by some environment var.


Nuno 



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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Steph Fox


Yes, it is. Check the system_with_timeout() function in the run-tests.php 
script.
There you've the timeout hardcoded ('$leak_check ? 300 : 60'). You would 
just need to make it configurable by some environment var.


I already tried hard-coding both tv_sec and tv_usec to 0 and it makes no 
difference here.


- Steph


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



[PHP-DEV] Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Lester Caine
Just trying to work out why my footprint was bigger than I expected running 
the windows 5.3.0-dev and I've got mysqlnd installed when I don't need it. How 
do I get rid of it or am I going have to compile my own builds in future?


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/lsces/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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



[PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Elizabeth M Smith
Lester Caine wrote:
> Just trying to work out why my footprint was bigger than I expected
> running the windows 5.3.0-dev and I've got mysqlnd installed when I
> don't need it. How do I get rid of it or am I going have to compile my
> own builds in future?
> 
It's on by default on windows, so you'll have to compile your own builds
if you don't want it - use the --without-mysqlnd flag on windows

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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Lester Caine

Elizabeth M Smith wrote:

Lester Caine wrote:

Just trying to work out why my footprint was bigger than I expected
running the windows 5.3.0-dev and I've got mysqlnd installed when I
don't need it. How do I get rid of it or am I going have to compile my
own builds in future?


It's on by default on windows, so you'll have to compile your own builds
if you don't want it - use the --without-mysqlnd flag on windows


Another reason not to switch to 5.3? :(

Any particular reason why it's been changed - I can't see anything I need it 
for.

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/lsces/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Pierre Joye
On Thu, Jun 19, 2008 at 2:39 PM, Lester Caine <[EMAIL PROTECTED]> wrote:
> Elizabeth M Smith wrote:
>>
>> Lester Caine wrote:
>>>
>>> Just trying to work out why my footprint was bigger than I expected
>>> running the windows 5.3.0-dev and I've got mysqlnd installed when I
>>> don't need it. How do I get rid of it or am I going have to compile my
>>> own builds in future?
>>>
>> It's on by default on windows, so you'll have to compile your own builds
>> if you don't want it - use the --without-mysqlnd flag on windows
>
> Another reason not to switch to 5.3? :(

Come on. Mysql has been always been enabled by default.

> Any particular reason why it's been changed - I can't see anything I need it
> for.

It is the main library used by all mysql modules, it replaces libmysql.

Cheers,
-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Steph Fox


Any particular reason why it's been changed - I can't see anything I need 
it for.


The other million or so who do.

- Steph


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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Lester Caine

Pierre Joye wrote:

On Thu, Jun 19, 2008 at 2:39 PM, Lester Caine <[EMAIL PROTECTED]> wrote:

Elizabeth M Smith wrote:

Lester Caine wrote:

Just trying to work out why my footprint was bigger than I expected
running the windows 5.3.0-dev and I've got mysqlnd installed when I
don't need it. How do I get rid of it or am I going have to compile my
own builds in future?


It's on by default on windows, so you'll have to compile your own builds
if you don't want it - use the --without-mysqlnd flag on windows

Another reason not to switch to 5.3? :(


Come on. Mysql has been always been enabled by default.


*NO* Mysql was REMOVED as the default in 5.0.0 after lots of requests from 
those of us who don't want it loaded. There was a democratic decision to 
remove it.



Any particular reason why it's been changed - I can't see anything I need it
for.


It is the main library used by all mysql modules, it replaces libmysql.


And should only be load if MySQl is required ...

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/lsces/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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



[PHP-DEV] Overloading

2008-06-19 Thread Tinsley, Mark
What about the addition of overloading for PHP 6?

I am not totally up to date on the developments of the parameter type
hints. I briefly read the meeting minutes for PHP 6.

What about with the type hints we have now?

class moo
{

public static function foo(FooClass $FooVar)
{
// do something 
}

public static function foo(BooClass $BooVar)
{
// do something
}
}


I have a project where we had to do a sort of pseudo overloading

Class moo
{
/**
 * Accept the superclass or any of its sub classes
 */
public static function foo(FooSuperClass $Foo)
{
switch (true)
{
case $Foo instanceof FooClass:
$method = 'fooFoo';
break;

case $Foo instanceof BooClass:
$method = 'fooBoo';
break;

default:
throw new Exception('Unrecognized type: ' .
get_class($Foo));
break;
}

call_user_func(array(self, $method), $Foo);
}

private static function fooFoo(FooClass $FooVar)
{
// do something
}

private static function fooBoo(BooClass $BooVar)
{
// do something
}
}

Mark



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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Travis Swicegood

On Jun 19, 2008, at 7:07 AM, Steph Fox wrote:



Yes, it is. Check the system_with_timeout() function in the run- 
tests.php script.
There you've the timeout hardcoded ('$leak_check ? 300 : 60'). You  
would just need to make it configurable by some environment var.


I already tried hard-coding both tv_sec and tv_usec to 0 and it  
makes no difference here.


I can add this to PHPT - it uses a timeout based on reading the open  
proc.  The only problem is that it is currently treated as an error.   
I could maybe add a new reporting level of timeout, though I do like  
the idea of having some sort of meta-data to conditionally skip tests.


Maybe a better solution is to add an --exclude  and ask  
people to either place potentially slow tests in tests/slow/, or name  
then .slow.phpt?  Being able to exclude a pattern of test  
names definitely has more use than just setting a timeout.


Thoughts?

-T

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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Steph Fox



Come on. Mysql has been always been enabled by default.


*NO* Mysql was REMOVED as the default in 5.0.0 after lots of requests from 
those of us who don't want it loaded. There was a democratic decision to 
remove it.


*NO*. MySQL was no longer bundled from 5.0.0 because MySQL AB went GPL on 
us. The mysqlnd library is their resolution for that problem.


- Steph


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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Nuno Lopes
Yes, it is. Check the system_with_timeout() function in the run-tests.php 
script.
There you've the timeout hardcoded ('$leak_check ? 300 : 60'). You would 
just need to make it configurable by some environment var.


I already tried hard-coding both tv_sec and tv_usec to 0 and it makes no 
difference here.


uhm, file a bug report then. It was supposed to work..
Nuno 



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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Steph Fox


I can add this to PHPT - it uses a timeout based on reading the open 
proc.


That's what the current run-tests does too. The problem is it isn't reliable 
cross-platform - we don't have any control over the select() function used 
by stream_select() except under Windows, where it doesn't work (I'm looking 
into that but can't see why).


The only problem is that it is currently treated as an error.   I could 
maybe add a new reporting level of timeout, though I do like  the idea of 
having some sort of meta-data to conditionally skip tests.


Maybe a better solution is to add an --exclude  and ask  people 
to either place potentially slow tests in tests/slow/, or name  then case>.slow.phpt?  Being able to exclude a pattern of test  names 
definitely has more use than just setting a timeout.


So what was wrong with the simple skipif and env var approach again? If 
you're going to mark a test to get run-tests to respond to it, it doesn't 
make a lot of difference whether you mark that test by its name or with a 
skipif line. The only difference is an untidy CVS directory.


I think the naming thing would be a better idea for something that's just 
starting out. It's a less good idea for a test suite that already exists 
IMHO.


- Steph



Thoughts?

-T

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




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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Steph Fox



uhm, file a bug report then. It was supposed to work..


There are some open on this already.

Also - Windows is the only environment where we actually have control over 
whether it works or not. Everything else relies on a system call.


- Steph 



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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Lester Caine

Steph Fox wrote:



Come on. Mysql has been always been enabled by default.


*NO* Mysql was REMOVED as the default in 5.0.0 after lots of requests 
from those of us who don't want it loaded. There was a democratic 
decision to remove it.


*NO*. MySQL was no longer bundled from 5.0.0 because MySQL AB went GPL 
on us. The mysqlnd library is their resolution for that problem.


MySQL was replaced by SQLite as the default database in the very first release 
of 5.0.0 http://www.php.net/ChangeLog-5.php#5.0.0b1
The PRIMARY reason was because of the number of non MySQL users who requested 
 that. CURRENTLY the default sql connection is SQLite so there is no need to 
add back in another option. The changes to the licence conditions just made 
the CHANGE of database easier ;)


MySQL should NOT be loaded by default as well as SQLite.

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/lsces/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Travis Swicegood

On Jun 19, 2008, at 8:26 AM, Steph Fox wrote:
I can add this to PHPT - it uses a timeout based on reading the  
open proc.


That's what the current run-tests does too. The problem is it isn't  
reliable cross-platform - we don't have any control over the select 
() function used by stream_select() except under Windows, where it  
doesn't work (I'm looking into that but can't see why).


This doesn't help you yet, but that's a moot point in PHPT as it uses  
COM under Windows as proc_* functions and the various stream  
functions are less than reliable.



So what was wrong with the simple skipif and env var approach  
again? If you're going to mark a test to get run-tests to respond  
to it, it doesn't make a lot of difference whether you mark that  
test by its name or with a skipif line. The only difference is an  
untidy CVS directory.


There's nothing wrong with that approach.  I'm trying to find  
something that addresses the problem (i.e., "how can I not run tests  
that are going to take a long time to run?"), while providing enough  
flexibility to answer other problems (i.e., "how can I skip X tests  
that I don't care about?").


If there's a way to address the problem without making it so  
specific, I'm all for it.




I think the naming thing would be a better idea for something  
that's just starting out. It's a less good idea for a test suite  
that already exists IMHO.


Agreed.  If we were to go this route, I'd actually consider adding a  
run-tests.ini or some such that allows you to configure things like  
excluded file patterns.


-T

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



Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP

2008-06-19 Thread Federico Lebron

Hi Dmitry,

As a lowly userspace developer, the | syntax is a bit confusing. If I 
see $x, $y | $a, $b, $c, my brain parses it as ($a, ($y | $a), $b, $c), 
since , has lower precedence than |. I'd think "syntax error", then 
"logical OR", but never "this refers to the variables I want imported to 
inside the closures".


Also, I'd like "lexical" a bit more for the same reasons discussed in 
the short array syntax ([1,2]) topic: a user faced with function($x, $y 
| $a, $b, $c) has nowhere to search for what | means.


I do, however, see the benefit of not changing the scanner and not 
breaking opcode caches. Would reusing "parent" be too much of a wtf?



Having little idea of how the internals work, would it be too 
complicated to hook "->" so if you say $obj->var(), and var holds a 
lambda function, for that function to be called instead of throwing a 
syntax error?
I know it seems hackish to add methods at runtime, but this would be to 
runkit's method addition what lambdas are to create_function.
IMO it would seem a bit more logical, if $obj->f = function(){echo 
"foo";};, to be able to do $obj->f() instead of $f = $obj->f; $f();, and 
knowing that $f() won't have access to $this (or at least, I wouldn't 
suppose it would in the second case).


I also agree that shipping it with 5.3 would be a bit too rushed, since 
this, like any other feature, needs to be debugged thoroughly if it's 
going into production (and going to change the API). 5.4 and 6.0 don't 
seem so bad, though.



- Federico Lebron


Dmitry Stogov wrote:

Hi Christian,

I took a look into your patch and found it too difficult.
So I implemented another patch (attached) which is based on your ideas.


From user's level of view it does exactly the same except for "lexical"

variables definition. I don't use any new reserver word because every
new reserved word is going to break some user code. I use the special
syntax for lambda function definition instead, which looks much clear
for me. The following code creates a lambda function with arguments $x,
$y and lexical variables $a, $b, $c.

$a = function($x, $y | $a, $b $c) {};

The patch shouldn't affect opcode caches and other extensions as it
doesn't change any structures. It uses the op_array->static_variables
for lexical variables.

The patch also fixes several small issues and adds some missing
functionality which didn't allow preg_replace_callback() (and may be
others) to work with lambda functions. Now the following example works fine.

foo($x[0].':'.$s);
};
  }
}

$x = new X;
$x = $x->bar("bye\n");
$s = 'abc';
preg_replace_callback('/[abc]/', $x, $s);
?>

It prints:

a:1:bye
b:2:1:bye
c:3:2:1:bye

Of course the patch doesn't break any existent tests.

Please review.

Thanks. Dmitry.


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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Steph Fox


There's nothing wrong with that approach.  I'm trying to find  something 
that addresses the problem (i.e., "how can I not run tests  that are going 
to take a long time to run?"), while providing enough  flexibility to 
answer other problems (i.e., "how can I skip X tests  that I don't care 
about?").


If there's a way to address the problem without making it so  specific, 
I'm all for it.


I mostly agree - I'm just looking at 'here and now' rather than 'when the 
nice new test suite stuff is done'. 'Here and now', there isn't a reliable 
way to set this up and skipif looks like the cleanest option.


I think the naming thing would be a better idea for something  that's 
just starting out. It's a less good idea for a test suite  that already 
exists IMHO.


Agreed.  If we were to go this route, I'd actually consider adding a 
run-tests.ini or some such that allows you to configure things like 
excluded file patterns.


That might not be a bad idea.

- Steph 



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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Steph Fox


MySQL was replaced by SQLite as the default database in the very first 
release of 5.0.0 http://www.php.net/ChangeLog-5.php#5.0.0b1


Yes.

The PRIMARY reason was because of the number of non MySQL users who 
requested that.


No. Will you please stop trying to rewrite history. There was an outcry when 
MySQL was unbundled - you were probably the only PHP user who was happy 
about it :)


- Steph 



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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Christopher Jones



Steph Fox wrote:

> So what was wrong with the simple skipif and env var approach again?

The problem is it only skips the test!

I'd like my slow tests to run (this generally occurs when I use a very
remote DB).  I end up manually increasing the timeout in stream_select()
in run-tests.sh.  This works for me on Linux.

If we make the timeout value adjustable, you can set it to a low value
so your slow tests are quickly aborted, and I can set it to a high
value so my tests are run.

Chris

--
Christopher Jones, Oracle
Email: [EMAIL PROTECTED]Tel:  +1 650 506 8630
Blog:  http://blogs.oracle.com/opal/   Free PHP Book: http://tinyurl.com/f8jad

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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Pierre Joye
On Thu, Jun 19, 2008 at 2:49 PM, Lester Caine <[EMAIL PROTECTED]> wrote:
> Pierre Joye wrote:
>>
>> On Thu, Jun 19, 2008 at 2:39 PM, Lester Caine <[EMAIL PROTECTED]> wrote:
>>>
>>> Elizabeth M Smith wrote:

 Lester Caine wrote:
>
> Just trying to work out why my footprint was bigger than I expected
> running the windows 5.3.0-dev and I've got mysqlnd installed when I
> don't need it. How do I get rid of it or am I going have to compile my
> own builds in future?
>
 It's on by default on windows, so you'll have to compile your own builds
 if you don't want it - use the --without-mysqlnd flag on windows
>>>
>>> Another reason not to switch to 5.3? :(
>>
>> Come on. Mysql has been always been enabled by default.
>
> *NO* Mysql was REMOVED as the default in 5.0.0 after lots of requests from
> those of us who don't want it loaded. There was a democratic decision to
> remove it.

I was not clear. Mysql has been (and still is) always enabled and
available by default in our Windows binaries.

>> It is the main library used by all mysql modules, it replaces libmysql.
>
> And should only be load if MySQl is required ...

Agreed, but I do not maintain mysqlnd (and not willing to :), can you
open a bug about that please?

Cheers,
-- 
Pierre

http://blog.thepimp.net | http://www.libgd.org

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



Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP

2008-06-19 Thread Dmitry Stogov
I don't like "lexical" keyword, because it can be used anywhere in 
function (e.q. inside "if" or loop statement), however lexical variables 
 must be the part of lambda function definition.


We can think about some better syntax, like

function ($x, $y) ($a, $b, $c) {};
function ($x, $y) [$a, $b, $c] {};

I like "|" separator more, but the syntax of definition is not so 
important for me. It just must be clean, and the "lexical" keyword 
doesn't provide clean definition.


I don't like the idea to add methods at runtime, as it can break shared 
data structures in multi-threaded environment.


Thanks. Dmitry.

Federico Lebron wrote:

Hi Dmitry,

As a lowly userspace developer, the | syntax is a bit confusing. If I 
see $x, $y | $a, $b, $c, my brain parses it as ($a, ($y | $a), $b, $c), 
since , has lower precedence than |. I'd think "syntax error", then 
"logical OR", but never "this refers to the variables I want imported to 
inside the closures".


Also, I'd like "lexical" a bit more for the same reasons discussed in 
the short array syntax ([1,2]) topic: a user faced with function($x, $y 
| $a, $b, $c) has nowhere to search for what | means.


I do, however, see the benefit of not changing the scanner and not 
breaking opcode caches. Would reusing "parent" be too much of a wtf?



Having little idea of how the internals work, would it be too 
complicated to hook "->" so if you say $obj->var(), and var holds a 
lambda function, for that function to be called instead of throwing a 
syntax error?
I know it seems hackish to add methods at runtime, but this would be to 
runkit's method addition what lambdas are to create_function.
IMO it would seem a bit more logical, if $obj->f = function(){echo 
"foo";};, to be able to do $obj->f() instead of $f = $obj->f; $f();, and 
knowing that $f() won't have access to $this (or at least, I wouldn't 
suppose it would in the second case).


I also agree that shipping it with 5.3 would be a bit too rushed, since 
this, like any other feature, needs to be debugged thoroughly if it's 
going into production (and going to change the API). 5.4 and 6.0 don't 
seem so bad, though.



- Federico Lebron


Dmitry Stogov wrote:

Hi Christian,

I took a look into your patch and found it too difficult.
So I implemented another patch (attached) which is based on your ideas.


From user's level of view it does exactly the same except for "lexical"

variables definition. I don't use any new reserver word because every
new reserved word is going to break some user code. I use the special
syntax for lambda function definition instead, which looks much clear
for me. The following code creates a lambda function with arguments $x,
$y and lexical variables $a, $b, $c.

$a = function($x, $y | $a, $b $c) {};

The patch shouldn't affect opcode caches and other extensions as it
doesn't change any structures. It uses the op_array->static_variables
for lexical variables.

The patch also fixes several small issues and adds some missing
functionality which didn't allow preg_replace_callback() (and may be
others) to work with lambda functions. Now the following example works 
fine.


foo($x[0].':'.$s);
};
  }
}

$x = new X;
$x = $x->bar("bye\n");
$s = 'abc';
preg_replace_callback('/[abc]/', $x, $s);
?>

It prints:

a:1:bye
b:2:1:bye
c:3:2:1:bye

Of course the patch doesn't break any existent tests.

Please review.

Thanks. Dmitry.


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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Steph Fox


Hi Chris,


If we make the timeout value adjustable, you can set it to a low value
so your slow tests are quickly aborted, and I can set it to a high
value so my tests are run.


It's easily enough done, it's just a separate issue.

I can easily put a workaround in the Windows version of select.c to make a 
0-second timeout work, but that's as far as it goes. The problem in 
run-tests (if anyone's interested - Travis seems to have a better solution) 
is that the actual read is always only 8192 bytes, and the actual API call 
never times out because stream_select() is reset at every iteration and 
called afresh. We'd need to be able to set a timeout limit in the run-tests 
script rather than in the call to stream_select(). And if we do that the 
tests of course fail, which isn't a good outcome.


So 'skipif' suits my needs better, but not yours. I'll add both.

- Steph



Chris

--
Christopher Jones, Oracle
Email: [EMAIL PROTECTED]Tel:  +1 650 506 8630
Blog:  http://blogs.oracle.com/opal/   Free PHP Book: 
http://tinyurl.com/f8jad 



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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Steph Fox



I was not clear. Mysql has been (and still is) always enabled and
available by default in our Windows binaries.


Not now, and not for a very long time.


Agreed, but I do not maintain mysqlnd (and not willing to :), can you
open a bug about that please?


It's not a bug. It was a democratic decision taken in the early days of 5.3.

- Steph 



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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Lester Caine

Steph Fox wrote:


MySQL was replaced by SQLite as the default database in the very first 
release of 5.0.0 http://www.php.net/ChangeLog-5.php#5.0.0b1


Yes.

The PRIMARY reason was because of the number of non MySQL users who 
requested that.


No. Will you please stop trying to rewrite history. There was an outcry 
when MySQL was unbundled - you were probably the only PHP user who was 
happy about it :)


And every other non-MySQL database user.
http://uk.php.net/manual/en/faq.databases.php#faq.databases.mysql.php5 
outlines some of the 'problems' but I can't find the other requests in the 
list archive. Although I have found ones from 2003 where I tell people HOW to 
enable MySQL again. I think the initial problem was that the extensions were 
not available for MySQL initially and took a while to appear?


WHY can't MySQL simply stay in the extensions with the rest of the database 
extensions. Why does it have to have preferential treatment? If applications 
need a little database to work they use SQLite otherwise we load a suitable 
alternative of our choice!


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/lsces/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Travis Swicegood

On Jun 19, 2008, at 9:03 AM, Steph Fox wrote:



There's nothing wrong with that approach.  I'm trying to find   
something that addresses the problem (i.e., "how can I not run  
tests  that are going to take a long time to run?"), while  
providing enough  flexibility to answer other problems (i.e., "how  
can I skip X tests  that I don't care about?").


If there's a way to address the problem without making it so   
specific, I'm all for it.


I mostly agree - I'm just looking at 'here and now' rather than  
'when the nice new test suite stuff is done'. 'Here and now', there  
isn't a reliable way to set this up and skipif looks like the  
cleanest option.


The only problem with that is everything you add I've got to add to  
my GSoC project so PHPT :-)



That might not be a bad idea.


I think the long-term goal should be the ability to "force skip"  
files based on an --exclude parameter, an ini conf file (looks for -- 
ini-file  or /tests.ini), and an ENV variable.  The first  
and last would just be separated by the PATH_SEPARATOR for regex  
patterns.


In addition, we can definitely make the time-out something that's  
settable via the command line and conf, but as you noted in your next  
email, that is a separate issue.


I've created a few tickets on these so we can make sure to track  
these issues:

* add exclude: http://phpt.info/ticket/69
* add timeout: http://phpt.info/ticket/70

-T

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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Lester Caine

Steph Fox wrote:



I was not clear. Mysql has been (and still is) always enabled and
available by default in our Windows binaries.


Not now, and not for a very long time.


Agreed, but I do not maintain mysqlnd (and not willing to :), can you
open a bug about that please?


It's not a bug. It was a democratic decision taken in the early days of 
5.3.

LINKS?
In fact I can see YOU commenting that it should not be enabled by default!
But that was 2007 - I see no agreement that it should be later ?

I will be opening a bug - if only to flag the need for a switch to disable it 
if it's not required.


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/lsces/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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



Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP

2008-06-19 Thread troels knak-nielsen
On Thu, Jun 19, 2008 at 4:37 PM, Dmitry Stogov <[EMAIL PROTECTED]> wrote:
> I don't like "lexical" keyword, because it can be used anywhere in function
> (e.q. inside "if" or loop statement), however lexical variables  must be the

That does sound wtf-y, indeed. Is that allowed with the global
keyword? Even if it is, I think it would be a sane limitation to put
on lexical, that it must come at the beginning of a function body
(Perhaps allowing global and static to precede it).

--
troels

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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Steph Fox



In fact I can see YOU commenting that it should not be enabled by default!
But that was 2007 - I see no agreement that it should be later ?


mysqlnd needs to be built-in statically.

I will be opening a bug - if only to flag the need for a switch to disable 
it if it's not required.


We have that. --disable-mysqlnd.

- Steph


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



Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP

2008-06-19 Thread Rodrigo Saboya

Dmitry Stogov escreveu:
I don't like "lexical" keyword, because it can be used anywhere in 
function (e.q. inside "if" or loop statement), however lexical variables 
 must be the part of lambda function definition.


I agree with Dmitry: Lexical variables belong to lambda function 
definition. It makes more sense to me. But I also agree that the 
proposed syntax might be a little misleading.



We can think about some better syntax, like

function ($x, $y) ($a, $b, $c) {};


This looks better


function ($x, $y) [$a, $b, $c] {};


Array confusion is to be expected with this syntax, I don't like it.

FWIW, I'd like to see this on 5.3.

regards
Rodrigo Saboya

I like "|" separator more, but the syntax of definition is not so 
important for me. It just must be clean, and the "lexical" keyword 
doesn't provide clean definition.


I don't like the idea to add methods at runtime, as it can break shared 
data structures in multi-threaded environment.


Thanks. Dmitry.


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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Pierre Joye
On Thu, Jun 19, 2008 at 4:55 PM, Steph Fox <[EMAIL PROTECTED]> wrote:
>
>> I was not clear. Mysql has been (and still is) always enabled and
>> available by default in our Windows binaries.
>
> Not now, and not for a very long time.

Can we stop with the nitpicking? mysql has been available.

>> Agreed, but I do not maintain mysqlnd (and not willing to :), can you
>> open a bug about that please?
>
> It's not a bug. It was a democratic decision taken in the early days of 5.3.

To have it by default, to have it always even when using --disable-all
and no mysql extensions are enabled? yes, it is bug.


-- 
Pierre

http://blog.thepimp.net | http://www.libgd.org

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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Christopher Jones



Steph Fox wrote:

So 'skipif' suits my needs better, but not yours. I'll add both.


Thanks Steph.

Chris

--
Christopher Jones, Oracle
Email: [EMAIL PROTECTED]Tel:  +1 650 506 8630
Blog:  http://blogs.oracle.com/opal/   Free PHP Book: http://tinyurl.com/f8jad

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



Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Steph Fox



I was not clear. Mysql has been (and still is) always enabled and
available by default in our Windows binaries.


Not now, and not for a very long time.


Can we stop with the nitpicking? mysql has been available.


To paraphrase Meatloaf, one out of three ain't bad :)


Agreed, but I do not maintain mysqlnd (and not willing to :), can you
open a bug about that please?


It's not a bug. It was a democratic decision taken in the early days of 
5.3.


To have it by default, to have it always even when using --disable-all
and no mysql extensions are enabled? yes, it is bug.


Can you build it as shared? I can't actually get --disable-all to work here, 
it keeps shouting about objects-out-dir being 'no'.


- Steph


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



Re: [PHP-DEV] [RFC] Strict type hints (parameter and return value)

2008-06-19 Thread Saulo Vallory
What if by type hint a parameter, php automatically tries to convert the
argument into that type and throws an exception ONLY if it couldn't be done?

for example:

function concat(string $a, string $b)
{
  return $a.$b;
}

I can do:
concat(1,'1');
concat(2.5,' pigs');
concat(new ConvertibleToStringObject, 15);

But if I do:

concat(new NonConvertibleToStringObject, 15);

PHP throws an exception saying the function needs a string, but the
parameter couldn't be converted...

Can this make everybody happy?

Cheers,

Saulo Vallory

On Wed, Jun 18, 2008 at 9:30 PM, Edward Z. Yang <
[EMAIL PROTECTED]> wrote:

> Fabrice VIGNALS wrote:
> > In mathematic, equal meen the same value AND the same nature.
> > The follow fact could be frustrating :
>
> Usually, context is good enough to disambiguate between the cases. The
> most prevalent convention in programming languages is = is assignment,
> and == is comparison (PHP adds === only because of its type-juggling
> system). Other languages have = as comparison, and := as assignment.
> Donald Knuth uses = as comparison, and a left arrow (<-) for assignment.
>
> --
>  Edward Z. YangGnuPG: 0x869C48DA
>  HTML Purifier  Anti-XSS Filter
>  [[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP-DEV] Overloading

2008-06-19 Thread Saulo Vallory
I'm developing a PHP framework and had the same issue sometimes... I think
it was already discussed in the list, did you searched the archives?

Saulo

On Thu, Jun 19, 2008 at 9:58 AM, Tinsley, Mark <[EMAIL PROTECTED]>
wrote:

> What about the addition of overloading for PHP 6?
>
> I am not totally up to date on the developments of the parameter type
> hints. I briefly read the meeting minutes for PHP 6.
>
> What about with the type hints we have now?
>
> class moo
> {
>
>public static function foo(FooClass $FooVar)
>{
>// do something
>}
>
>public static function foo(BooClass $BooVar)
>{
>// do something
>}
> }
>
>
> I have a project where we had to do a sort of pseudo overloading
>
> Class moo
> {
>/**
> * Accept the superclass or any of its sub classes
> */
>public static function foo(FooSuperClass $Foo)
>{
>switch (true)
>{
>case $Foo instanceof FooClass:
>$method = 'fooFoo';
>break;
>
>case $Foo instanceof BooClass:
>$method = 'fooBoo';
>break;
>
>default:
>throw new Exception('Unrecognized type: ' .
> get_class($Foo));
>break;
>}
>
>call_user_func(array(self, $method), $Foo);
>}
>
>private static function fooFoo(FooClass $FooVar)
>{
>// do something
>}
>
>private static function fooBoo(BooClass $BooVar)
>{
>// do something
>}
> }
>
> Mark
>
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP-DEV] Re: Disable mysqlnd in PHP5.3.0

2008-06-19 Thread Elizabeth M Smith
Steph Fox wrote:
> 
> Can you build it as shared? I can't actually get --disable-all to work
> here, it keeps shouting about objects-out-dir being 'no'.
> 
> - Steph
> 
Ah, shoot, the disable-all thing... that's a configure bug steph, and I
have a patch to fix it sitting around here somewhere

Elizabeth

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



Re: [PHP-DEV] [PATCH] make it possible to skip very slow tests

2008-06-19 Thread Greg Beaver

Travis Swicegood wrote:

On Jun 19, 2008, at 9:03 AM, Steph Fox wrote:



There's nothing wrong with that approach.  I'm trying to find  
something that addresses the problem (i.e., "how can I not run tests  
that are going to take a long time to run?"), while providing enough  
flexibility to answer other problems (i.e., "how can I skip X tests  
that I don't care about?").


If there's a way to address the problem without making it so  
specific, I'm all for it.


I mostly agree - I'm just looking at 'here and now' rather than 'when 
the nice new test suite stuff is done'. 'Here and now', there isn't a 
reliable way to set this up and skipif looks like the cleanest option.


The only problem with that is everything you add I've got to add to my 
GSoC project so PHPT :-)



That might not be a bad idea.


I think the long-term goal should be the ability to "force skip" files 
based on an --exclude parameter, an ini conf file (looks for --ini-file 
 or /tests.ini), and an ENV variable.  The first and last 
would just be separated by the PATH_SEPARATOR for regex patterns.


The ini file is a great idea, as one can create groupings of test suites 
 independent of the tests.


Greg

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



[PHP-DEV] Fw: [PHP-CVS] cvs: php-src(PHP_5_3) /win32/build confutils.js

2008-06-19 Thread Steph Fox


Hey Jani,

You can run but you can't hide ;)  I'm assuming this is down to you, since 
you moved ereg.


I won't even pretend to understand browscap. Please remember to kill this 
build exclusion if/when you fix it?


Thanks,

- Steph

- Original Message - 
From: "Steph Fox" <[EMAIL PROTECTED]>

To: <[EMAIL PROTECTED]>
Sent: Thursday, June 19, 2008 6:43 PM
Subject: [PHP-CVS] cvs: php-src(PHP_5_3) /win32/build confutils.js




sfox Thu Jun 19 17:43:38 2008 UTC

 Modified files:  (Branch: PHP_5_3)
   /php-src/win32/build confutils.js
 Log:
 - ext/standard currently has a dependency on ext/ereg thanks to 
browscap.c


http://cvs.php.net/viewvc.cgi/php-src/win32/build/confutils.js?r1=1.60.2.1.2.8.2.12&r2=1.60.2.1.2.8.2.13&diff_format=u
Index: php-src/win32/build/confutils.js
diff -u php-src/win32/build/confutils.js:1.60.2.1.2.8.2.12 
php-src/win32/build/confutils.js:1.60.2.1.2.8.2.13
--- php-src/win32/build/confutils.js:1.60.2.1.2.8.2.12 Thu Jun 19 17:14:43 
2008

+++ php-src/win32/build/confutils.js Thu Jun 19 17:43:38 2008
@@ -17,7 +17,7 @@
  +--+
*/

-// $Id: confutils.js,v 1.60.2.1.2.8.2.12 2008/06/19 17:14:43 sfox Exp $
+// $Id: confutils.js,v 1.60.2.1.2.8.2.13 2008/06/19 17:43:38 sfox Exp $

var STDOUT = WScript.StdOut;
var STDERR = WScript.StdErr;
@@ -347,7 +347,7 @@

 var snapshot_build_exclusions = new Array(
 'debug', 'crt-debug', 'lzf-better-compression',
- 'php-build', 'snapshot-template',
+ 'php-build', 'snapshot-template', 'ereg',
 'pcre-regex', 'fastcgi', 'force-cgi-redirect',
 'path-info-check', 'zts', 'ipv6', 'memory-limit',
 'zend-multibyte', 'fd-setsize', 'memory-manager', 't1lib'



--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




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



Re: [PHP-DEV] [PATCH] unix path separators in spl

2008-06-19 Thread Stanislav Malyshev

Hi!

The attached patch implements spl_unixify_path_separators(). If it's 


I'm afraid that automatically applying slash conversions to all results 
returned by SPL file functions - if that's what this patch does - may be 
unwanted. This way SPL functions and regular file functions would return 
different file names, which can be harmful if these names are used as 
keys, compared, etc.


--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED]   http://www.zend.com/
(408)253-8829   MSN: [EMAIL PROTECTED]

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



Re: [PHP-DEV] deprecation status of $str{42} versus $str[42]

2008-06-19 Thread Andrei Zmievski
That's why there is TextIterator. And it's also much faster (in PHP 6) 
than iterating through string using indexes.


-Andrei

Stefan Walk wrote:

On Tuesday 17 June 2008 08:27:37 Arvids Godjuks wrote:

2008/6/16 Edward Z. Yang <[EMAIL PROTECTED]>:

PHP userland code may not treat strings as first class arrays, but
that's certainly how they are represented internally.

Anyway, it would be neat if we could get that foreach syntax to work. I
get sick of for($i = 0, $c = strlen($str); $i < $c; $i++) very quickly.

Totaly agree, the best example from the whole thread



You're not learning from the mistakes of other languages (ruby in this case, 
which removed Enumerable from String in 1.9) ... "foreach" makes no sense for 
strings, because it's unclear what you want (with unicode terminology here, 
as this is for php6): 
"for each byte" "for each codeunit" "for each codepoint", or "for each line", 
or ... if you want to use foreach in your example, just do 
foreach (str_split($str) as $value) { ...


Regards,
Stefan



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



Re: [PHP-DEV] [RFC] Strict type hints (parameter and return value)

2008-06-19 Thread Timm Friebe

Hi,

I like this generally, but cannot live with the BC issues raised. 
Introducing all type names as keywords will make "class Object", "class 
Integer" and so on give a syntax error.


That's actually not true, the patch does not introduce new keywords.


Hrm, the Wiki states it does:

 http://wiki.php.net/rfc/typehint#bc_break1

If this can be worked out by other means, cool:)

- Timm 


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



Re: [PHP-DEV] extensions status, to move to pecl or to drop

2008-06-19 Thread Timm Friebe

Hi,
been busy again at work, sorry for the late answer.


I can look into setting up a "cruise-control"-like infrastructure on our
dev-machines that'll run these periodically.


Thanks for the offer, that would be very helpful.  Is it possible to
have it for windows as well? It could also help if we can get one
access to fix the possible bugs, as I don't have any sybase licenses
or access to any kind of Sybase server (other developers neither).


I think it could be done on Windows also - let's see if my budget allows for 
a Windows testing machine - if not, I'll (shh) use the production 
server:)


- Timm 



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



Re: [PHP-DEV] [PATCH] unix path separators in spl

2008-06-19 Thread Stanislav Malyshev

Hi!

On the other hand, the only code likely to be broken would be 
platform-specific code written for Windows boxes - how much of that is 
likely to be out there? Another point is that, although Windows *writes* 


Any amount, but I don't see why it would break only windows-specific 
code. If I use any other function to get filenames, and/or use 
PATH_SEPARATOR to compose names, and then use these names in the same 
context as those converting SPL function, I'd get different names on 
Windows even if my application was written in most generic way. Do I 
miss something?


'\', these days it's capable of recognising either separator. So it 
really would just be down to path comparisons.


Path comparison is important.
--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED]   http://www.zend.com/
(408)253-8829   MSN: [EMAIL PROTECTED]

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



Re: [PHP-DEV] [PATCH] unix path separators in spl

2008-06-19 Thread Steph Fox


Any amount, but I don't see why it would break only windows-specific 
code. If I use any other function to get filenames, and/or use 
PATH_SEPARATOR to compose names, and then use these names in the same 
context as those converting SPL function, I'd get different names on 
Windows even if my application was written in most generic way. Do I 
miss something?


Doesn't PATH_SEPARATOR use DEFAULT_SLASH?

'\', these days it's capable of recognising either separator. So it 
really would just be down to path comparisons.


Path comparison is important.


I thought so too until I couldn't find any broken tests.

- Steph


--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED]   http://www.zend.com/
(408)253-8829   MSN: [EMAIL PROTECTED]


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



Re: [PHP-DEV] [PATCH] unix path separators in spl

2008-06-19 Thread Steph Fox



The attached patch implements spl_unixify_path_separators(). If it's


I'm afraid that automatically applying slash conversions to all results 
returned by SPL file functions - if that's what this patch does - may be 
unwanted. This way SPL functions and regular file functions would return 
different file names, which can be harmful if these names are used as 
keys, compared, etc.


Paths. Mm, possibly.

On the other hand, the only code likely to be broken would be 
platform-specific code written for Windows boxes - how much of that is 
likely to be out there? Another point is that, although Windows *writes* 
'\', these days it's capable of recognising either separator. So it really 
would just be down to path comparisons.


I'm actually wondering how much harm it would do to make DEFAULT_SLASH 
generic...


- Steph 



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



Re: [PHP-DEV] Selectable error messages

2008-06-19 Thread Marcus Boerger
Hello Lester,

Wednesday, June 18, 2008, 9:14:52 AM, you wrote:

> OK - I've got PHP5.3.0-dev up at the moment in order to test the Firebird 
> stuff, so display_errors is on. I need it on anyway while testing code.

> The 'problem' I am having is that of cause none of the other PHP stuff I'm 
> using is currently not compatible with PHP5.3 so generates a lot of deprecated
> warnings in particular.

> Current one is phpDocumentor which uses is_a() extensively, and has a function
> to replicate it for backwards compatibility.

Hey guys, I thought we undeprecated is_a()?

there is no need whatsoever to deprecate it.

Best regards,
 Marcus


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



Re: [PHP-DEV] [PATCH] unix path separators in spl

2008-06-19 Thread Stanislav Malyshev

Hi!

Windows even if my application was written in most generic way. Do I 
miss something?


Doesn't PATH_SEPARATOR use DEFAULT_SLASH?


Should be DIRECTORY_SEPARATOR and it's "\" on windows (PATH_SEPARATOR is 
";" ). Do you propose to change it to "/"?



Path comparison is important.


I thought so too until I couldn't find any broken tests.


With all due respect to phpt, these are very primitive code samples 
testing very narrow functional areas. They do not come anywhere near the 
stuff people do in real-life apps, combining different functions and 
extensions.

--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED]   http://www.zend.com/
(408)253-8829   MSN: [EMAIL PROTECTED]

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



Re: [PHP-DEV] [PATCH] unix path separators in spl

2008-06-19 Thread Marcus Boerger
Hello Steph,

  how about having this as an option inside the SPL classes that gets
turned on by Phar automatically? Inside SPL we could have it as a user
set-only flag.

marcus

Wednesday, June 18, 2008, 10:28:40 PM, you wrote:

> Index: ext/spl/spl_directory.c
> ===
> RCS file: /repository/php-src/ext/spl/spl_directory.c,v
> retrieving revision 1.45.2.27.2.23.2.22
> diff -u -r1.45.2.27.2.23.2.22 spl_directory.c
> --- ext/spl/spl_directory.c 18 Jun 2008 10:05:29 -  
> 1.45.2.27.2.23.2.22
> +++ ext/spl/spl_directory.c 18 Jun 2008 17:16:39 -
> @@ -185,6 +185,9 @@
> intern->file_name_len =
> spprintf(&intern->file_name, 0, "%s%c%s",
> 
> spl_filesystem_object_get_path(intern, NULL TSRMLS_CC),
>  DEFAULT_SLASH, 
> intern->u.dir.entry.d_name);
> +#ifdef PHP_WIN32
> +   spl_unixify_path_separators(intern->file_name, 
> intern->file_name_len);
> +#endif
> break;
> }
> }
> @@ -1196,6 +1199,9 @@
> subdir->u.dir.sub_path_len = 
> strlen(intern->u.dir.entry.d_name);
> subdir->u.dir.sub_path =
> estrndup(intern->u.dir.entry.d_name, subdir->u.dir.sub_path_len);
> }
> +#ifdef PHP_WIN32
> +   spl_unixify_path_separators(intern->u.dir.sub_path, 
> intern->u.dir.sub_path_len);
> +#endif
> subdir->info_class = intern->info_class;
> subdir->file_class = intern->file_class;
> subdir->oth = intern->oth;
> @@ -1227,6 +1233,9 @@
>  
> if (intern->u.dir.sub_path) {
> len = spprintf(&sub_name, 0, "%s%c%s",
> intern->u.dir.sub_path, DEFAULT_SLASH, intern->u.dir.entry.d_name);
> +#ifdef PHP_WIN32
> +   spl_unixify_path_separators(sub_name, len);
> +#endif
> RETURN_STRINGL(sub_name, len, 0);
> } else {
> RETURN_STRING(intern->u.dir.entry.d_name, 1);
> Index: ext/spl/spl_directory.h
> ===
> RCS file: /repository/php-src/ext/spl/spl_directory.h,v
> retrieving revision 1.12.2.5.2.4.2.10
> diff -u -r1.12.2.5.2.4.2.10 spl_directory.h
> --- ext/spl/spl_directory.h 20 May 2008 21:46:50 -  
> 1.12.2.5.2.4.2.10
> +++ ext/spl/spl_directory.h 18 Jun 2008 17:10:18 -
> @@ -112,6 +112,20 @@
> return (spl_filesystem_object*)((char*)it -
> XtOffsetOf(spl_filesystem_object, it));
>  }
>  
> +#ifdef PHP_WIN32
> +static inline void spl_unixify_path_separators(char *path, int path_len)
> +{
> +   char *s;
> +
> +   /* unixify win paths */
> +   for (s = path; s - path < path_len; ++s) {
> +   if (*s == '\\') {
> +   *s = '/';
> +   }
> +   }
> +}
> +#endif
> +
>  #define SPL_FILE_OBJECT_DROP_NEW_LINE  0x0001 /* drop new lines */
>  #define SPL_FILE_OBJECT_READ_AHEAD 0x0002 /* read on rewind/next 
> */
>  #define SPL_FILE_OBJECT_SKIP_EMPTY 0x0006 /* skip empty lines */




Best regards,
 Marcus


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



Re: [PHP-DEV] Selectable error messages

2008-06-19 Thread Pierre Joye
Hi Marcus,

On Thu, Jun 19, 2008 at 8:57 PM, Marcus Boerger <[EMAIL PROTECTED]> wrote:
> Hello Lester,
>
> Wednesday, June 18, 2008, 9:14:52 AM, you wrote:
>
>> OK - I've got PHP5.3.0-dev up at the moment in order to test the Firebird
>> stuff, so display_errors is on. I need it on anyway while testing code.
>
>> The 'problem' I am having is that of cause none of the other PHP stuff I'm
>> using is currently not compatible with PHP5.3 so generates a lot of 
>> deprecated
>> warnings in particular.
>
>> Current one is phpDocumentor which uses is_a() extensively, and has a 
>> function
>> to replicate it for backwards compatibility.
>
> Hey guys, I thought we undeprecated is_a()?
>
> there is no need whatsoever to deprecate it.

We did, I would appreciate if you can nicely remove the E_DEPRECATED from it :)

Cheers,
-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

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



Re: [PHP-DEV] [PATCH] unix path separators in spl

2008-06-19 Thread Steph Fox


Hi Marcus,


 how about having this as an option inside the SPL classes that gets
turned on by Phar automatically? Inside SPL we could have it as a user
set-only flag.


You are brilliant. I owe you a beer :)

- Steph

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



Re: [PHP-DEV] [PATCH] unix path separators in spl

2008-06-19 Thread Steph Fox


Hi Stas,


Doesn't PATH_SEPARATOR use DEFAULT_SLASH?


Should be DIRECTORY_SEPARATOR


Bleh, must be nearly switching-off time

and it's "\" on windows (PATH_SEPARATOR is ";" ). Do you propose to change 
it to "/"?


dirsep_str[0] = DEFAULT_SLASH;
dirsep_str[1] = '\0';
REGISTER_STRING_CONSTANT("DIRECTORY_SEPARATOR", dirsep_str, 
CONST_CS|CONST_PERSISTENT);



Path comparison is important.


I thought so too until I couldn't find any broken tests.


With all due respect to phpt, these are very primitive code samples 
testing very narrow functional areas. They do not come anywhere near the 
stuff people do in real-life apps, combining different functions and 
extensions.


Fair point. I like Marcus' idea tho'.

- Steph



--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED]   http://www.zend.com/
(408)253-8829   MSN: [EMAIL PROTECTED]

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




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



Re: [PHP-DEV] [PATCH] unix path separators in spl

2008-06-19 Thread Stanislav Malyshev

Hi!


Fair point. I like Marcus' idea tho'.


As long as the default stays the same and doesn't hurt anybody not 
touching the option - go for it.

--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED]   http://www.zend.com/
(408)253-8829   MSN: [EMAIL PROTECTED]

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



Re: [PHP-DEV] Algorithm Optimizations - string search

2008-06-19 Thread Michal Dziemianko

Hi,
I am also sorry for delay - got ill recently and spend a day in bed  
after night at emergency. I am working on other things now, and hope  
to post some patches soon. I will create patch for zend_memnstr as  
you suggest and post it here probably tomorrow. I have some ideas/ 
implementations/data already prepared for other functions (not only  
string related) but haven't got time to publish it neither here, nor  
on the page (http://212.85.117.53/gsoc/), but will try to do it till  
Monday.

Michal

On 2008-06-17, at 23:57, Nuno Lopes wrote:


Hi,

Sorry for taking so long to answer, but I'm trying to catch up last  
stuff.
It's known that usually to optimize things for longer inputs you  
usually end up making things for short inputs worst. So IMHO, I  
think you should have the len==1 optimization and then use the KMP  
algorithm. Your implementation can be further optimized (at least  
on 32 bits machines), but seems ok for now.
I suggest you to produce a final patch, send it here, and then move  
on to optimize other things (like strtr() that I'm sure wikipedia  
guys will appreciate).


Nuno


- Original Message -

Hello again
I have setup small page where I am publishing all the profiling  
and evaluation results. It is here: http://83.168.205.202/~michal/  
standard15/
So far I have put there function usage profile, zend_memnstr   
analysis, stripos and strrpos analysis including some charts etc.  
CVS  diffs where applicable are also posted along with comparison  
of  original and patched code.

Michal

On 2008-06-11, at 09:47, Stanislav Malyshev wrote:


Hi!


Here are some statistics:
- average haystack length: 624.2
- average needle length: 1.9 ! -> 63% of needles of length 1
- avg length of haystacks shorter than avg: 41.0 -> 85% of all  
haystacks

- avg length of haystacks  longer than avg: 5685.11


I think it would be interesting to see same excluding 1-char   
needles since in this case it should do one-char lookup (btw, if  
we  don't do it on C level, it might be a good idea to).



Although strpos implements fix for that, some other functions   
don't. My idea

is than to implement ZEND_MEMNSTR once again in shape:
if (needle_len = 1)
here just linear sweep
else if haystack_len < 5000 (5000 is arbitrary - maybe some  
more  tests

needed to choose good value)
original implementation (as it is the best one in this case)
else
BM/KMP (i think BM will be better in this case, as some people
suggested)


I'm not sure very big haystacks really worth the trouble - how  
many  of them are used? It may be interesting to see medians  
instead of  averages for that. But len=1 I think worth having  
special case.

--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED]   http://www.zend.com/
(408)253-8829   MSN: [EMAIL PROTECTED]






Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP

2008-06-19 Thread Andrei Zmievski
Yes, I would rather put it in 5.4 (or whatever the next version) is and 
make sure that along with lambdas/closures we have a way of referring to 
functions/methods as first-class objects.


-Andrei

Marcus Boerger wrote:

Hello Stanislav,

  nicely put but not in agreement with the PHP world. First we cannot add
a new feature like this in a mini release as it comes with an API change.
And second PHP is not anywhere close so we'd have to do it in a PHP 5.4
and personally I would like to avoid it.

marcus

Tuesday, June 17, 2008, 9:19:56 PM, you wrote:


Hi!



Johannes, what's your take on this one for 5.3?


I'm not Johannes and I didn't review the proposal in detail yet, but I 
think we have enough for 5.3 right now. I'd think we better concentrate 
on tying the loose ends and rolling beta out and then moving towards the 
release than adding more and more features and never releasing it. 5.3 
is not the final release until the end of times, there will be 5.4 etc. 
and 6, so there will be ample opportunity to add stuff. And 5.3 has 
enough stuff to be released, there's no rush to add more new things, 
especially radically new ones. My opinion is that we better take some 
time with it and not tie it to 5.3.

--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED]   http://www.zend.com/
(408)253-8829   MSN: [EMAIL PROTECTED]





Best regards,
 Marcus




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



[PHP-DEV] cleaning up the functions - any volunteers?

2008-06-19 Thread Stanislav Malyshev

Hi!

While we nearing the release of 5.3 (hopefully?), there are many 
functions in the PHP code which still use old parameter parsing API 
(zend_get_parameters_ex) instead of the new one (zend_parse_parameters).


I have cleaned up Zend engine functions, converting them to the new API, 
but there are about 1000 instances throughout PHP code (especially 
ext/standard) which still use the old way. This way is less correct, 
inconsistent with the new code, gives worse error messages, more prone 
to various bugs, etc. All new extensions and functions use the new way, 
and the only reason for keeping the old way in the code seems to be that 
nobody cleaned it up. Somebody has to bring the old ones into sync, and 
I don't think I personally will have time to do it in near timeframe. So 
if anybody could step up to that - by doing at least part of the work - 
that'd be great. The work is pretty simple, taking something like:


zval **data;

if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &data) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(data);

and move it into:

char *str;
int str_len;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, 
&str_len) == FAILURE) {

return;
}

and of course convert use of data zval into use of str.

This needs to be done carefully as not to break things on some more 
tricky functions which may get arguments of multiple types, etc. Also, 
some tests which check error messages may need to be fixed since new API 
gives more detailed messages.

zend_parse_parameters documented here:
http://www.php.net/manual/en/internals2.ze1.zendapi.php
though some of the newer parameters aren't (C, h, f, Z) so one may need 
to look at the code at zend_API.c.


P.S. if some genius would invent a script to automate that - it'd be 
awesome, but I don't have very high hopes on that. :)

--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED]   http://www.zend.com/
(408)253-8829   MSN: [EMAIL PROTECTED]

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



Re: [PHP-DEV] cleaning up the functions - any volunteers?

2008-06-19 Thread Felipe Pena
Hello

Em Qui, 2008-06-19 às 16:06 -0700, Stanislav Malyshev escreveu:
> Hi!
> 
> While we nearing the release of 5.3 (hopefully?), there are many 
> functions in the PHP code which still use old parameter parsing API 
> (zend_get_parameters_ex) instead of the new one (zend_parse_parameters).
> 

Yeah, I have noticed... That's also in my TODO.

-- 
Regards,
Felipe Pena.


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



Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP

2008-06-19 Thread Christian Seiler

Hi Dmitry,

First of all: Your patch does really simplify things internally quite a
bit - I like it. I have a few issues though:


The patch shouldn't affect opcode caches and other extensions as it
doesn't change any structures.


I don't see a problem in changing structures for either extensions nor
opcode caches - as long as only entries are added. Binary compability
with PHP 5.2 is not provided anyway (by neither 5.3 nor 6) and source
compability is not affected if the old members are not touched or their
semantics change.


It uses the op_array->static_variables for lexical variables.


That's a point I don't like. Although you use IS_CONSTANT to cleverly
mask lexical variables, I really think a separate hash table would be a
far better idea, especially for code maintainability.


The patch also fixes several small issues and adds some missing
functionality which didn't allow preg_replace_callback() (and may be
others) to work with lambda functions.


Oh yes, I somehow missed that, thanks!


Please review.


I (personally) have some smaller issues with the patch and one big
issue:

Smaller issues:

 * A separate hash table for the lexical variables would be much cleaner
   in my eyes.

 * The segfault that occurs with my patch still occurs with yours (see
   below for an example)

But the one big issue is the syntax: ($foo | $bar) is just extremely
painful in my eyes. I wouldn't want to use it - and it would be quite
confusing (which side are the normal parameters, which side are the
lexical vars?). I do see your point that the 'lexical' keyword inside
the function body to actually have an effect on the function semantics
is not optimal and that the list of lexical variables is probably better
placed in the function definition. I therefore propose the following syntax:

function (parameters) { }   // no closure, simply lambda
function (parameters) KEYWORD (lexical) { } // closure with lexical vars

KEYWORD could be for example 'use'. That probably describes best what
the function does: Use/import those variables from the current scope.
Example:

return function ($x) use ($s) {
  static $n = 0;
  $n++;
  $s = $n.':'.$s;
  $this->foo($x[0].':'.$s);
};

As for simply omitting the keyword, e.g. function () () - as already
suggested: I don't like that syntax either. Although I'm not a fan of
too much language verbosity (that's why I don't like Fortran, Basic and
Pascal), I think in this case, a little more verbosity wouldn't hurt -
and typing 'use' is just 3 additional characters.

Now for the examples for the smaller issues:

Segfault:



This crashes - due to the fact that the currently used op_array is
destroyed upon destruction of the variable. This could get even more
interesting if the closure called itself recursively. My proposal is to
create a copy (but not a reference, just do a normal copy, for resources
or objects that will just do the trick) of the variable internally in
zend_call_function and zend_do_fcall_common_helper into a dummy zval and
destroy that zval after the function call ended. That way, the GC won't
kick in until after the execution of the closure. In zend_call_function
that's easy - in zend_do_fcall_common helper we have the problem that
the variable containing the closure is no longer available. An idea
could be that the INIT_FCALL functions always additionally push the
lambda zval to the argument stack (inside the function it will be
ignored) and the fcall_common_helper will remove that zval from the
stack prior to returning (and free it). If a non-closure is called, NULL
(or an empty zval or whatever) could be pushed to the stack instead.
Hmm, perhap's I'll have a better idea tomorrow.

Anyway, since Andi suggested to use objects instead of resources, I'd
like to use your patch as a starting point, if there are no objections.

Regards,
Christian

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



Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP

2008-06-19 Thread Alexander Wagner
First, a comment from haskell-land:
http://www.haskell.org/pipermail/haskell-cafe/2008-June/044533.html
http://www.haskell.org/pipermail/haskell-cafe/2008-June/thread.html#44379

On Wednesday 18 June 2008, Christian Seiler wrote:
> Frankly, I don't really see a problem with using references. It fits
> into what's already there in PHP and it assures that closures have the
> necessary properties to make them useful.

References are necessary, but an easy way to obtain copies of variables from 
the lexical context would be really nice.

I have been introduced to functional programming through Haskell, where values 
are immutable, so a reference is basically the same as a copy. I like this 
behaviour because it makes closures distinctly non-dangerous by default.

Getting the same behaviour out of PHP should not be as difficult as this:
   for ($i = 0; $i < 10; $i++) {
 $loopIndex = $i;
 $arr[$i] = function () { lexical $loopIndex; return $loopIndex; };
 unset ($loopIndex);
   }
This is not only quite a hassle (making beer much cheaper than water, so to 
speak), I also believe it to be error-prone. A lot of programmers are going 
to forget that unset().

I would prefer something like this:
   for ($i = 0; $i < 10; $i++) {
 $arr[$i] = function () { lexical_copy $i; return $i; };
   }

An alternative would be to let lexical behavie like function parameters:
- copies by default
 lexical $x;
- objects referenced by default
 lexical $obj;
- other references optional
 lexical &$y;

Of course this would make lexical behave quite differently from global in this 
regard, decreasing consistency, but f*ck global, nobody should use that 
anyway. Better to have nice lexical closures.

Gesundheit
  Wag

-- 
Be careful about reading health books. You may die of a misprint.
 - Mark Twain

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



Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP

2008-06-19 Thread Stanislav Malyshev

Hi!


First, a comment from haskell-land:
http://www.haskell.org/pipermail/haskell-cafe/2008-June/044533.html
http://www.haskell.org/pipermail/haskell-cafe/2008-June/thread.html#44379


Thanks for the links, very interesting. Even a couple of comments in the 
thread going beyond "PHP sucks" and really discussing the matter. :)

Best account is this:

* A closure must only keep alive the varables it references, not the
whole pad on which they are allocated
[Check]
* A closure must be able to call itself recursively (via a
higher-order function typically)
[Check, since you can use variable you assigned closure to inside the 
closure, if I understand correctly]

* Multiple references to the same body of code with different bindings
must be able to exist at the same time
[Check]
* Closures must be nestable.
[Dunno - does the patch allow nesting and foo(1)(2)?]


Getting the same behaviour out of PHP should not be as difficult as this:


Well, I don't see any other way if you use references. Variables _are_ 
mutable in PHP. You could, of course, use copies, but then you'd lose 
ability to update. Maybe if we drop "lexical" and use Dmitry's proposal of


$arr[$i] = function () ($i) { return $i; };

where ($i) would be copy, (&$i) would be by-ref, then it'd be easier to 
control it. I know function()() is weird, but not everybody likes 
lexical either :) Maybe we can do lexical &$y, but that looks weird too...


Of course this would make lexical behave quite differently from global in this 


I wouldn't spend too much thought on making lexical work like global. 
global is for different purpose (and with $GLOBALS is obsolete anyway :)

--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED]   http://www.zend.com/
(408)253-8829   MSN: [EMAIL PROTECTED]

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



Re: [PHP-DEV] cleaning up the functions - any volunteers?

2008-06-19 Thread Philip Olson

While we nearing the release of 5.3 (hopefully?), there are many
functions in the PHP code which still use old parameter parsing API
(zend_get_parameters_ex) instead of the new one  
(zend_parse_parameters).




Yeah, I have noticed... That's also in my TODO.


Where is the Felipe fan club signup sheet?

Regards,
Philip

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



Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP

2008-06-19 Thread Alexander Wagner
On Friday 20 June 2008, Stanislav Malyshev wrote:
> * A closure must be able to call itself recursively (via a
> higher-order function typically)
> [Check, since you can use variable you assigned closure to inside the
> closure, if I understand correctly]

This is a matter of implementation rather than design, so it should be 
resolved by testing rather than by reading the spec ;-)

> Well, I don't see any other way if you use references. Variables _are_
> mutable in PHP.

They are also copied by default (passed by value). So if lexical used copies 
by default (and passed objects by reference), it would be consistent with all 
of php except for global. Let global be the outcast and be consistent with 
exerything else. As long as references are easily available, I think this is 
the much better trade-off. And it makes water slightly cheaper than beer.

> I know function()() is weird

And would become weirder if foo(1)(2) is implemented. +1 to that by the way, 
allowing dereferencing for methods ( $obj->method1()->method2(); ) but not 
for functions is kinda mean.

Maybe function( ) [ ] { } instead of function( ) ( ) { }
That way the different parts actually look different. Also, confusion with 
arrays should be pretty much impossible here, both for the parser and human 
readers.

I prefer "lexical", though. Functional programming is not the default paradigm 
in PHP, so rather err on the side of explicitness.

Gesundheit
  Wag

-- 
Remember, growing older is mandatory. Growing up is optional.

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



Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP

2008-06-19 Thread Stanislav Malyshev

Hi!

Yes, I would rather put it in 5.4 (or whatever the next version) is and 
make sure that along with lambdas/closures we have a way of referring to 
functions/methods as first-class objects.


Maybe we could make some object handler so that $object($foo) would work 
and treat object as "functional object" called on $foo and then have 
both reflection and closure object implement it?

--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED]   http://www.zend.com/
(408)253-8829   MSN: [EMAIL PROTECTED]

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