Re: [PHP-DEV] file streams metadata

2011-03-14 Thread Stas Malyshev

Hi!

Here's an RFC:
http://wiki.php.net/rfc/streammetadata

Patch link inside.
--
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



[PHP-DEV] preg_replace does not replace all occurrences

2011-03-14 Thread Martin Scotta
I chose the simplest example to show the preg_replace behavior, there are
better (and safer) ways to scape slash characters.
Anyways, *is this the expected preg_replace behavior?*

 Martin

?php
function test($str) {
static $re = '/(^|[^])\'/';
static $change = '$1\\\'';

echo $str, PHP_EOL,
preg_replace($re, $change, $str), PHP_EOL, PHP_EOL;
}

test(str '' str); // bug?
test(str \\'\\' str); // ok
test('str'); // ok
test(\'str\'); // ok


Expected:

str '' str
str \'\' str

str \'\' str
str \'\' str

'str'
\'str\'

\'str\'
\'str\'


Result:

str '' str
str \'' str

str \'\' str
str \'\' str

'str'
\'str\'

\'str\'
\'str\'


 Martin Scotta


Re: [PHP-DEV] preg_replace does not replace all occurrences

2011-03-14 Thread Richard Quadling
On 14 March 2011 15:18, Martin Scotta martinsco...@gmail.com wrote:
 ?php
 function test($str) {
    static $re = '/(^|[^])\'/';
    static $change = '$1\\\'';

    echo $str, PHP_EOL,
        preg_replace($re, $change, $str), PHP_EOL, PHP_EOL;
 }

 test(str '' str); // bug?
 test(str \\'\\' str); // ok
 test('str'); // ok
 test(\'str\'); // ok


Your regex is ...



(^|[^])'

Options: case insensitive; ^ and $ match at line breaks

Match the regular expression below and capture its match into
backreference number 1 «(^|[^])»
   Match either the regular expression below (attempting the next
alternative only if this one fails) «^»
  Assert position at the beginning of a line (at beginning of the
string or after a line break character) «^»
   Or match regular expression number 2 below (the entire group fails
if this one fails to match) «[^]»
  Match a single character NOT present in the list below «[^]»
 A \ character «\\»
 A \ character «\\»
Match the character “'” literally «'»



I think [^] is wrong and you want it to be ...

(?!)

or

(?!\\{2})


With that, the output is ...

str '' str
str \'\' str

str \'\' str
str \\'\\' str

'str'
\'str\'

\'str\'
\\'str\\'



-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



Re: [PHP-DEV] native php annotations

2011-03-14 Thread guilhermebla...@gmail.com
Hi all,

I promise myself to not revamp this discussion again, but it wasn't me
this time!

@Etienne: That RFC is outdated.
Since the last feedback form internals list, a lot of changes have
been made to that RFC. Maybe I should update it ASAP so you can
clearly understand what have changed to be compatible with current PHP
syntax.

If you are interested, Pierrick moved all the recent developments to a
github repository, which can be reached here:
https://github.com/adoy/PHP-Annotations

Take a look at some tests:
https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/parser_021.phpt
https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/ReflectionParameter_getAnnotations_003.phpt
https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/ReflectionClass_getAnnotations_004.phpt

Also, there's even an alternative patch that support positioned
parameters instead of named ones.
We just have to reach an agreement with what PHP core want.

@Marcelo: While your proposal looks very good, it lacks of the support
to nested Annotation.
Consider how userland/framework would use your idea. For example,
Symfony2 supports validation of data inside classes inspired on
JSR-303 (Bean Validation).

Symfony2 takes an advantage of a library Doctrine group (which I'm a
core member) created by parsing docblocks. When we created this
parser, I created this RFC with the good intention that PHP could
benefit of this known feature to enhance current userland
developments.
The first thing you need is your application still running ok with and
without comments. This already breaks all suggestions of creating a
PECL extension of docblock parser.



I'd like to see what people think about it and make something IN on
next PHP major version.



Cheers,

On Sun, Mar 13, 2011 at 8:07 PM, Pierre Joye pierre@gmail.com wrote:
 On Sun, Mar 13, 2011 at 11:02 PM, Marcelo Gornstein marce...@gmail.com 
 wrote:
 I don't believe the patch was anywhere near an accepted state back then,
 sadly.
 Are you saying there wont be annotations in PHP? Is there any way to
 contribute to make this feature accepted and available?

 No, only that no compromise has been reached on annotation support.


 --
 Pierre

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

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





-- 
Guilherme Blanco
Mobile: +55 (16) 9215-8480
MSN: guilhermebla...@hotmail.com
São Paulo - SP/Brazil

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



Re: [PHP-DEV] preg_replace does not replace all occurrences

2011-03-14 Thread Ben Schmidt

On 15/03/11 2:18 AM, Martin Scotta wrote:

I chose the simplest example to show the preg_replace behavior,


You've GOT to be kidding. The SIMPLEST?!

How about an example that doesn't require escaping ALL the interesting
characters involved?

Here's a modified version that I think it quite a bit simpler:

?php
function test($str) {
   static $re = '/(^|[^a])b/';
   static $change = '$1ab';

   echo $str, PHP_EOL; // input
   echo preg_replace($re, $change, $str), PHP_EOL, PHP_EOL; // output
}

test(str bb str); // bug?
test(str abab str); // ok
test(b str b); // ok
test(ab str ab); // ok
?

The way I interpret it, it should put an 'a' before every 'b' that is
not already preceded by an 'a'.

But the buggy case gives 'str abb str' rather than the expected
'str abab str'.

It does look like a bug to me.

Ben.




there are
better (and safer) ways to scape slash characters.
Anyways, *is this the expected preg_replace behavior?*

  Martin

?php
function test($str) {
 static $re = '/(^|[^])\'/';
 static $change = '$1\\\'';

 echo $str, PHP_EOL,
 preg_replace($re, $change, $str), PHP_EOL, PHP_EOL;
}

test(str '' str); // bug?
test(str \\'\\' str); // ok
test('str'); // ok
test(\'str\'); // ok


Expected:

str '' str
str \'\' str

str \'\' str
str \'\' str

'str'
\'str\'

\'str\'
\'str\'


Result:

str '' str
str \'' str

str \'\' str
str \'\' str

'str'
\'str\'

\'str\'
\'str\'


  Martin Scotta



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



Re: [PHP-DEV] preg_replace does not replace all occurrences

2011-03-14 Thread Ben Schmidt

On 15/03/11 5:38 AM, Ben Schmidt wrote:

On 15/03/11 2:18 AM, Martin Scotta wrote:

I chose the simplest example to show the preg_replace behavior,


You've GOT to be kidding. The SIMPLEST?!

How about an example that doesn't require escaping ALL the interesting
characters involved?

Here's a modified version that I think it quite a bit simpler:

?php
function test($str) {
static $re = '/(^|[^a])b/';
static $change = '$1ab';

echo $str, PHP_EOL; // input
echo preg_replace($re, $change, $str), PHP_EOL, PHP_EOL; // output
}

test(str bb str); // bug?
test(str abab str); // ok
test(b str b); // ok
test(ab str ab); // ok
?

The way I interpret it, it should put an 'a' before every 'b' that is
not already preceded by an 'a'.

But the buggy case gives 'str abb str' rather than the expected
'str abab str'.

It does look like a bug to me.


Actually, no it doesn't.

The behaviour is correct.

Matches cannot overlap. Since the character preceding 'b' is part of the
match, there is only one match in the string 'str bb str'. The match is
' b'. After that match, the

You actually want an assertion. I think this:

static $re = '/(^|(?!a))b/';

Ben.




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



Re: [PHP-DEV] native php annotations

2011-03-14 Thread Marcelo Gornstein
The presented patch is just a quick and dirty work that I could put
together in 2 days, with knowledge of the zend engine. Thanks to some
tips from Pierrick, I'm slowly improving its quality.

However my ideal goals are pretty close to what you have done in your
rfc. Today Pierrick added the possibility to annotate method
parameters just like in the patch I sent, so I'm happy I already
contributed with something ;)

I made the patch for similar reasons. I'm the author of Ding (IoC/DI
container) and I really dont like having to use doc blocks to support
annotations. I think this is an increasing need generally speaking in
the php world. If PHP is to be considered some kind of agile
language, it needs some kind of metadata handling (in this case,
annotations).

I think other things can be added to the rfc, like having some
annotations supported by php itself (@Init, @Destroy, @Configuration).
This would need to be instantiated and run as soon as the annotation
is detected. This could be accomplished by either php or c code, so
the behavior can be extended via pecl extensions and/or normal php
code.


On Mon, Mar 14, 2011 at 3:02 PM, guilhermebla...@gmail.com
guilhermebla...@gmail.com wrote:
 Hi all,

 I promise myself to not revamp this discussion again, but it wasn't me
 this time!

 @Etienne: That RFC is outdated.
 Since the last feedback form internals list, a lot of changes have
 been made to that RFC. Maybe I should update it ASAP so you can
 clearly understand what have changed to be compatible with current PHP
 syntax.

 If you are interested, Pierrick moved all the recent developments to a
 github repository, which can be reached here:
 https://github.com/adoy/PHP-Annotations

 Take a look at some tests:
 https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/parser_021.phpt
 https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/ReflectionParameter_getAnnotations_003.phpt
 https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/ReflectionClass_getAnnotations_004.phpt

 Also, there's even an alternative patch that support positioned
 parameters instead of named ones.
 We just have to reach an agreement with what PHP core want.

 @Marcelo: While your proposal looks very good, it lacks of the support
 to nested Annotation.
 Consider how userland/framework would use your idea. For example,
 Symfony2 supports validation of data inside classes inspired on
 JSR-303 (Bean Validation).

 Symfony2 takes an advantage of a library Doctrine group (which I'm a
 core member) created by parsing docblocks. When we created this
 parser, I created this RFC with the good intention that PHP could
 benefit of this known feature to enhance current userland
 developments.
 The first thing you need is your application still running ok with and
 without comments. This already breaks all suggestions of creating a
 PECL extension of docblock parser.



 I'd like to see what people think about it and make something IN on
 next PHP major version.



 Cheers,

 On Sun, Mar 13, 2011 at 8:07 PM, Pierre Joye pierre@gmail.com wrote:
 On Sun, Mar 13, 2011 at 11:02 PM, Marcelo Gornstein marce...@gmail.com 
 wrote:
 I don't believe the patch was anywhere near an accepted state back then,
 sadly.
 Are you saying there wont be annotations in PHP? Is there any way to
 contribute to make this feature accepted and available?

 No, only that no compromise has been reached on annotation support.


 --
 Pierre

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

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





 --
 Guilherme Blanco
 Mobile: +55 (16) 9215-8480
 MSN: guilhermebla...@hotmail.com
 São Paulo - SP/Brazil




-- 

--
// I don't sleep. I coffee.
Make everything as simple as possible, but not simpler. -- Albert Einstein
The class object inherits from Chuck Norris.
Chuck Norris can divide by zero and can unit test an entire
application with a single assert.
There’s a lot of work happening behind the scenes, courtesy of the
Spring AOP framework
Why do I have this nagging hunch that you have no idea what you're doing?
Any society that would give up a little liberty to gain a little
security will deserve neither and lose both - Benjamin Franklin

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



Re: [PHP-DEV] preg_replace does not replace all occurrences

2011-03-14 Thread Hannes Landeholm
What is more likely to be wrong? Your understanding of a specific
regex pattern (which happens to be full of escapes making it
incredibly hard to read) or the implementation of preg_replace?

~Hannes

On 14 March 2011 16:18, Martin Scotta martinsco...@gmail.com wrote:

 I chose the simplest example to show the preg_replace behavior, there are
 better (and safer) ways to scape slash characters.
 Anyways, *is this the expected preg_replace behavior?*

  Martin

 ?php
 function test($str) {
    static $re = '/(^|[^])\'/';
    static $change = '$1\\\'';

    echo $str, PHP_EOL,
        preg_replace($re, $change, $str), PHP_EOL, PHP_EOL;
 }

 test(str '' str); // bug?
 test(str \\'\\' str); // ok
 test('str'); // ok
 test(\'str\'); // ok

 
 Expected:

 str '' str
 str \'\' str

 str \'\' str
 str \'\' str

 'str'
 \'str\'

 \'str\'
 \'str\'

 
 Result:

 str '' str
 str \'' str

 str \'\' str
 str \'\' str

 'str'
 \'str\'

 \'str\'
 \'str\'


  Martin Scotta

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



Re: [PHP-DEV] SplFileObject Countable

2011-03-14 Thread Sebastian Marek
Hello,

That makes perfect sense. I have raised a feature request and have attached
a patch containing both countLines() method implementation and phpt tests.

thx

On Sun, Mar 13, 2011 at 9:39 PM, Etienne Kneuss col...@php.net wrote:

 On Mar 11 23:22:04, Sebastian Marek wrote:
  Hi,
 
  I have recently used SplFileObject to work with files. I was lacking a
 bit
  of functionality in there regarding counting number of lines in a given
  file. Although I could just load contents of the file to an array and
 check
  it size, I thought it would be nice to have SplFileObject Countable.
 
  Here is an example implementation I made tonight that seems to work well
 -
  https://gist.github.com/866767 . Is it something you think would be
 worth
  adding to the existing SplFileObject? Is the implementation any good? I
  reused some of the existing logic to avoid breaking
 'spl_filesystem_object'
  internal integrity, but maybe it would make sense to make it work with
 the
  stream itself.

 In my oppinion, it does not make sense to implement countable for this
 use. Countable should be implemented on classes where calling count() on
 them is not ambiguous, i.e. the size of a collection.

 There is no reason why count() on a file should be the number of lines,
 why not words, or bytes?

 I'd however be happy with a new countLines() method.

 Best,

 
  If it's fine I can write some unit tests to cover this and then submit a
  complete patch.
 
  Regards
  --
  Sebastian Marek
  proo...@gmail.com
 
  Follow me online at:
  Blog: http://criticallog.thornet.net/
  Twitter: http://twitter.com/proofek
  Linkedin: http://uk.linkedin.com/in/sebastianmarek
  Ohloh: http://www.ohloh.net/accounts/proofek
  http://twitter.com/proofek




-- 
Sebastian Marek
proo...@gmail.com

Follow me online at:
Blog: http://criticallog.thornet.net/
Twitter: http://twitter.com/proofek
Linkedin: http://uk.linkedin.com/in/sebastianmarek
Ohloh: http://www.ohloh.net/accounts/proofek
http://twitter.com/proofek