Stas Malyshev | 1 Oct 03:06 2010

Re: [PHP-DEV] Understanding the benefits of handling Bucket data in PHP's HashTables

Hi!

The bucket can store 2 types of data - either any random piece of data 
(ARPD) or a pointer. When bucket with ARPD is created/deleted, the 
memory storing ARPD is allocated/freed. When bucket holding a pointer is 
created/freed, nothing special happens since the pointer is stored 
inside the bucket.
zend_hash_find returns the pointer to the data stored, not the copy of 
it (since you might want to modify it), that's the reason why it's 
void** - it's pointer to the data, which is by itself either pointer 
passed to hash or pointer to allocated piece for ARPD.
-- 
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

Adam Harvey | 1 Oct 04:52 2010
Picon
Picon

Re: [PHP-DEV] Expose compare_function() to userspace

On 1 October 2010 06:26, Stas Malyshev <smalyshev <at> sugarcrm.com> wrote:
>> Can we make it an operator-like (is_a for example) instead? It could
>> be more efficient.
>
> Operator has a downside that you can't pass it as a parameter. We could have
> something like <=> (spaceship operator!) or even cmp though :)

Yeah, I think if it's going to be available, it has to be as a
function so it can be used as a callback.

I can cook up a patch for an operator version in addition to the
functional version, although I don't know that the performance benefit
would necessarily be worth the extra complication (or potential
confusion for users of having two ways to skin the same cat).

Adam

--

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

Adam Harvey | 1 Oct 04:57 2010
Picon
Picon

Re: [PHP-DEV] RFC: Comparable interface

For what it's worth, I'm planning to update the RFC later today with
an updated SPL-less patch and the start of a Q&A section similar to
what we've had in the other RFCs. I'll send an e-mail when it's ready.

On 1 October 2010 04:28, Stas Malyshev <smalyshev <at> sugarcrm.com> wrote:
> It is not clear from the RFC, if the engine encounters $a <= $b, what
> actually happens?
> E.g.:
> 1. Is only $a checked for Comparable or also $b?

Both $a and $b are checked.

> 2. How it is ensured that if $a < $b then $b > $a?

That's up to the userspace developer to get right when they're
implementing their compareTo method. I expect the manual would have a
dire warning about the possible consequences of not making them
equivalent.

> 3. Would sorting work with it?

Yes.

> 4. If both $a and $b are objects with different compare functions, how it is
> determined whose function is used? Note that operators like == are assumed
> to be commutative, and less/more operators are assumed to be commutative in
> pairs, like above.

The left operand wins, so $a.

(Continue reading)

Adam Harvey | 1 Oct 10:38 2010
Picon
Picon

[PHP-DEV] Re: RFC: Comparable interface

On 30 September 2010 21:33, Adam Harvey <aharvey <at> php.net> wrote:
> I've just written an RFC (with a patch against trunk) to implement a
> Comparable interface similar to that in Java — in effect, allowing
> object instances to be compared with semantics defined in userspace.
> This is admittedly at the lower end of RFC-worthy proposals, but it's
> a good system, and I'd like to see it used a little more. Plus, it's
> good practice for the more interesting stuff to come. :)

I've updated the RFC with a fresh patch that doesn't involve SPL at
all and attempted to incorporate some of the questions and answers so
far into the RFC. I've also added a section for concerns with the RFC;
I've attempted to distil the concerns I've seen so far, but please
feel free to edit that list if specific concerns are misrepresented or
unrepresented.

Links:

RFC: http://wiki.php.net/rfc/comparable
Patch v2: http://www.adamharvey.name/patches/comparable-v2.diff.txt

Thanks,

Adam

--

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

Gustavo Lopes | 1 Oct 11:27 2010
Picon

Re: [PHP-DEV] Re: RFC: Comparable interface

On Fri, 01 Oct 2010 09:38:19 +0100, Adam Harvey <aharvey <at> php.net> wrote:

> On 30 September 2010 21:33, Adam Harvey <aharvey <at> php.net> wrote:
>> I've just written an RFC (with a patch against trunk) to implement a
>> Comparable interface similar to that in Java — in effect, allowing
>> object instances to be compared with semantics defined in userspace.
>> This is admittedly at the lower end of RFC-worthy proposals, but it's
>> a good system, and I'd like to see it used a little more. Plus, it's
>> good practice for the more interesting stuff to come. :)
>
> I've updated the RFC with a fresh patch that doesn't involve SPL at
> all and attempted to incorporate some of the questions and answers so
> far into the RFC. I've also added a section for concerns with the RFC;
> I've attempted to distil the concerns I've seen so far, but please
> feel free to edit that list if specific concerns are misrepresented or
> unrepresented.
>
> Links:
>
> RFC: http://wiki.php.net/rfc/comparable
> Patch v2: http://www.adamharvey.name/patches/comparable-v2.diff.txt
>

Here's a new concern: I find a bad idea to call compareTo *before*  
'compare_objects'. This means that if in your internal class you define  
your own comparison logic with 'compare_objects', you cannot make sure the  
userland subclasses won't completely replace your logic by implementing  
Comparable. So to prevent this you'd have to implement 'Comparable'  
yourself...

(Continue reading)

Pierre Joye | 1 Oct 11:38 2010
Picon

Re: [PHP-DEV] Re: RFC: Comparable interface

hi Adam,

Thanks for writing and updating a RFC, always the best way to propose
new features :)

On Fri, Oct 1, 2010 at 10:38 AM, Adam Harvey <aharvey <at> php.net> wrote:
> On 30 September 2010 21:33, Adam Harvey <aharvey <at> php.net> wrote:
>> I've just written an RFC (with a patch against trunk) to implement a
>> Comparable interface similar to that in Java — in effect, allowing
>> object instances to be compared with semantics defined in userspace.
>> This is admittedly at the lower end of RFC-worthy proposals, but it's
>> a good system, and I'd like to see it used a little more. Plus, it's
>> good practice for the more interesting stuff to come. :)
>
> I've updated the RFC with a fresh patch that doesn't involve SPL at
> all and attempted to incorporate some of the questions and answers so
> far into the RFC. I've also added a section for concerns with the RFC;
> I've attempted to distil the concerns I've seen so far, but please
> feel free to edit that list if specific concerns are misrepresented or
> unrepresented.

Maybe to get a context about how other languages work (or do not work)
with these similar features, it could be interesting to look at the
python (2.5) documentation:
http://docs.python.org/release/2.5.2/ref/customization.html

As I would be in favor of having a compareTo interface for similar
objects, I worry a bit about comparing apple and pear. Yes, an apple
can be greater than a pear in real world but the wtf is somehow huge
in a php context. That's why I share Stas or Gustavo thoughts about
(Continue reading)

Michael Wallner | 1 Oct 11:57 2010
Picon
Picon

Re: [PHP-DEV] Expose compare_function() to userspace

On 10/01/2010 12:26 AM, Stas Malyshev wrote:
> Hi!
>
>> Can we make it an operator-like (is_a for example) instead? It
>> could be more efficient.
>
> Operator has a downside that you can't pass it as a parameter. We
> could have something like <=> (spaceship operator!) or even cmp
> though :)

OT: Stas, could you please include the name of the Person(s) you're
quoting in your mails.  It's extremely hard to follow the conversation
if there are posts of you in it.

Thank you!
Mike

--

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

Hannes Magnusson | 1 Oct 18:45 2010
Picon

Re: [PHP-DEV] Expose compare_function() to userspace

On Thu, Sep 30, 2010 at 16:44, Adam Harvey <aharvey <at> php.net> wrote:
> Well, while I'm sending e-mails...
>
> Unrelated to the Comparable RFC, are there any objections to adding a
> function that simply wraps compare_function()? It's depressingly
> common to end up writing a construct like the following in comparison
> callbacks, so I think we might as well encapsulate the pattern in an
> actual function:
>
> if ($a < $b) {
>  return -1;
> }
> elseif ($a > $b) {
>  return 1;
> }
> return 0;

I'm a bit confused...

Are you proposing a new PHP function to check if 2 integers are equal?
The usecase being a callback function for u*sort()?

What happens when it gets passed an string? or an object with a
__toString() ? the string "100$ USD"?

I am a bit skeptical here..
Sure, I have written that code snippet millions of times, but I have
also written that between() snippet million times..
Don't think it deserves to become a PHP core function though.
When I write the function I can atleast control what happens with
(Continue reading)

Stas Malyshev | 2 Oct 03:18 2010

[PHP-DEV] rfc2616 datetime format?

Hi!

Any reason why DateTime doesn't have a constant for RFC2616 (HTTP) date 
format? RFC1123 and 'r' are _almost_ there but 2616 explicitly states TZ 
must be "GMT" and 1123 format produces +0000 instead.
-- 
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

Jingcheng Zhang | 3 Oct 07:40 2010
Picon

[PHP-DEV] Is this behavior expected?

Hello internals,

I've occurred an inconsistent problem:

<?php
C::f();
abstract class C {
    public static function f() {
        echo 'foo';
    }
}
?>

This works and print "foo".

<?php
C::f();
interface I {}
abstract class C implements I {
    public static function f() {
        echo 'foo';
    }
}
?>

The result is "Fatal error: Class 'C' not found". Is this result expected?
Why?

--

-- 
Best regards,
(Continue reading)


Gmane