Re: [PHP-DEV] [RFC] Implement a LoggerInterface to PHP
On 11/08/2012 04:42 AM, Florin Razvan Patan wrote: Hello, After a talk on the Symfony framework here: https://github.com/symfony/symfony/issues/5911 Long story short, the point that @Seldaek suggestion to have a common interface for loggers actually makes sense and the best way to have it would be to have PHP include it by default. I'm not sure exactly what amount of work this implies, nor my C skills are existent, but with PHP having such an interface available it would help standardize things in the PHP world. Also, I'm not sure if this could be backported into existing PHP 5.3 or PHP 5.4 versions but this would make sense to consider it for PHP 5.5. What do you guys think? Could this be considered to be included in PHP? Thank you for your time. Best regards, Florin Florin Patan The possibility of opening security holes or otherwise breaking existing applications because new functionality has been introduced by default, is such that inclusions of new functionality *by*default* are usually Very Bad Luck and should imo always be avoided. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Object comparison
On 11/08/2012 05:07 PM, Sara Golemon wrote: From: http://php.net/manual/en/language.operators.comparison.php An object compared to anything which is not a bool, null, or object should result in the object appearing to be greater than the other operand. For example: $a = new stdClass(); $b = new stdClass(); var_dump(null $a); var_dump(false $a); var_dump(true == $a); var_dump($a == $b); var_dump(0 $a); var_dump(1 $a); // false var_dump(2 $a); // false var_dump(foo $a); var_dump(2 $a); var_dump(tmpfile() $a); Based on docs, I expect all nine of these to yield true, however in practice, the two marked false come out as false because the RHS object is converted to an integer (1), contrary to the docs. Doc bug? Or code bug? I'm inclined to call it a code bug, but wanted others' thoughts. -Sara You seem to be reporting a bug (contrary to the docs), but you might be suggesting that the doc be corrected (since doc and behaviour should always match). I would suggest being very careful about implementing something as central as a change to how comparisons are made, that ought to be approached with great caution because it has the potential for breaking a huge amount of existing code. [It does occur to me however, simply as a point of interest, that objects traditionally have both a constructor and a destructor, and the idea of objects also having a comparator makes a certain amount of sense; a default object comparator might implement the currently defined comparisons while allowing derived classes to override the default behaviour and leaving comparisons not involving objects undisturbed.] Comparing objects to scalars is really an apples/oranges comparision to begin with. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] Implement a LoggerInterface to PHP
hi! On Thu, Nov 8, 2012 at 12:42 PM, Florin Razvan Patan florinpa...@gmail.com wrote: Hello, After a talk on the Symfony framework here: https://github.com/symfony/symfony/issues/5911 Long story short, the point that @Seldaek suggestion to have a common interface for loggers actually makes sense and the best way to have it would be to have PHP include it by default. I'm not sure exactly what amount of work this implies, nor my C skills are existent, but with PHP having such an interface available it would help standardize things in the PHP world. Also, I'm not sure if this could be backported into existing PHP 5.3 or PHP 5.4 versions but this would make sense to consider it for PHP 5.5. What do you guys think? Could this be considered to be included in PHP? Thank you for your time. We already had a discussion about having pure interfaces in PHP, as standard. The idea was rejected. This is the role of the PSR group, or other similar entities to sit down together to define such things. Cheers, -- 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
RE: [PHP-DEV] Object comparison
I would like to place a suggestion for comparing objects (I hope it is no problem, because this does not have anything to do with Sara's question - but it came to my mind when I read her mail). It would be a great feature if objects could be compared to other objects with , and the other operators, like it is suggested in RFC https://wiki.php.net/rfc/comparable The DateTime class offers this feature - it would be nice if this could be made usable for userland classes/objects, too. Best regards Christian Stoller -Original Message- From: p...@golemon.com [mailto:p...@golemon.com] On Behalf Of Sara Golemon Sent: Friday, November 09, 2012 1:07 AM To: PHP internals Subject: [PHP-DEV] Object comparison From: http://php.net/manual/en/language.operators.comparison.php An object compared to anything which is not a bool, null, or object should result in the object appearing to be greater than the other operand. For example: $a = new stdClass(); $b = new stdClass(); var_dump(null $a); var_dump(false $a); var_dump(true == $a); var_dump($a == $b); var_dump(0 $a); var_dump(1 $a); // false var_dump(2 $a); // false var_dump(foo $a); var_dump(2 $a); var_dump(tmpfile() $a); Based on docs, I expect all nine of these to yield true, however in practice, the two marked false come out as false because the RHS object is converted to an integer (1), contrary to the docs. Doc bug? Or code bug? I'm inclined to call it a code bug, but wanted others' thoughts. -Sara -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Object comparison
Hi, Maybe it goes way to far, but there is a PECL-extension [1], that allows to overload every(?) operator. However, it seems to be unmaintained for 6 years now and will probably not work anymore, but it may be usable as a starting point. Python provides this too [2] Regards, Sebastian [1] http://pecl.php.net/package/operator [2] http://docs.python.org/2/reference/datamodel.html#special-method-names 2012/11/9 Christian Stoller stol...@leonex.de I would like to place a suggestion for comparing objects (I hope it is no problem, because this does not have anything to do with Sara's question - but it came to my mind when I read her mail). It would be a great feature if objects could be compared to other objects with , and the other operators, like it is suggested in RFC https://wiki.php.net/rfc/comparable The DateTime class offers this feature - it would be nice if this could be made usable for userland classes/objects, too. Best regards Christian Stoller -Original Message- From: p...@golemon.com [mailto:p...@golemon.com] On Behalf Of Sara Golemon Sent: Friday, November 09, 2012 1:07 AM To: PHP internals Subject: [PHP-DEV] Object comparison From: http://php.net/manual/en/language.operators.comparison.php An object compared to anything which is not a bool, null, or object should result in the object appearing to be greater than the other operand. For example: $a = new stdClass(); $b = new stdClass(); var_dump(null $a); var_dump(false $a); var_dump(true == $a); var_dump($a == $b); var_dump(0 $a); var_dump(1 $a); // false var_dump(2 $a); // false var_dump(foo $a); var_dump(2 $a); var_dump(tmpfile() $a); Based on docs, I expect all nine of these to yield true, however in practice, the two marked false come out as false because the RHS object is converted to an integer (1), contrary to the docs. Doc bug? Or code bug? I'm inclined to call it a code bug, but wanted others' thoughts. -Sara -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP-DEV] Object comparison
hi! On Fri, Nov 9, 2012 at 1:07 AM, Sara Golemon poll...@php.net wrote: From: http://php.net/manual/en/language.operators.comparison.php An object compared to anything which is not a bool, null, or object should result in the object appearing to be greater than the other operand. For example: $a = new stdClass(); $b = new stdClass(); var_dump(null $a); var_dump(false $a); var_dump(true == $a); var_dump($a == $b); var_dump(0 $a); var_dump(1 $a); // false var_dump(2 $a); // false var_dump(foo $a); var_dump(2 $a); var_dump(tmpfile() $a); Based on docs, I expect all nine of these to yield true, however in practice, the two marked false come out as false because the RHS object is converted to an integer (1), contrary to the docs. Doc bug? Or code bug? I'm inclined to call it a code bug, but wanted others' thoughts. As stated by other before, comparing scalars and objects sound wrong in the 1st place. But I have seen way too many weird codes relying on weird things :). That's why I would not be in favor of changing anything in this area as some code out there may rely on that (have the feeling that object comparison has been like that since 5.0). Cheers, -- 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
Re: [PHP-DEV] Object comparison
On Fri, Nov 9, 2012 at 2:18 PM, Christian Stoller stol...@leonex.de wrote: I would like to place a suggestion for comparing objects (I hope it is no problem, because this does not have anything to do with Sara's question - but it came to my mind when I read her mail). It would be a great feature if objects could be compared to other objects with , and the other operators, like it is suggested in RFC https://wiki.php.net/rfc/comparable The DateTime class offers this feature - it would be nice if this could be made usable for userland classes/objects, too. I really like that idea, and the patch looks pretty good and looks backward compatible. I'm +1 with it I'm also +1 with patching the doc to describe the full default compare behavior. Julien.Pauli -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Object comparison
On Fri, Nov 9, 2012 at 2:00 PM, jpauli jpa...@php.net wrote: On Fri, Nov 9, 2012 at 2:18 PM, Christian Stoller stol...@leonex.de wrote: I would like to place a suggestion for comparing objects (I hope it is no problem, because this does not have anything to do with Sara's question - but it came to my mind when I read her mail). It would be a great feature if objects could be compared to other objects with , and the other operators, like it is suggested in RFC https://wiki.php.net/rfc/comparable The DateTime class offers this feature - it would be nice if this could be made usable for userland classes/objects, too. I really like that idea, and the patch looks pretty good and looks backward compatible. I'm +1 with it I'm also +1 with patching the doc to describe the full default compare behavior. Another spot in the docs I would enjoy discussion about ,,=,= comparing two objects: http://php.net/manual/en/language.oop5.object-comparison.php I notice this behavior is suggested in a comment for use in an array_uintersect callback: http://php.tonnikala.org/manual/el/function.array-uintersect.php#72841 Indeed, trying to intersect two arrays of objects with a user callback 'works' with the comparison operator, but maybe this is just luck, or subject to BC break later? ?php class myclass { function __construct($name) { $this-name = $name; } } $o1 = new myclass('o1'); $o2 = new myclass('o2'); $o3 = new myclass('o3'); $o4 = new myclass('o4'); $a1 = array($o1, $o2, $o3); $a2 = array($o3, $o2, $o4); var_dump(array_uintersect($a1, $a2, function($v1, $v2) { if($v1 === $v2) return 0; if($v1 $v2) return 1; return -1; })); I'd expect the comparison there to be roughly equivalent to if(spl_object_hash($v1) spl_object_hash($v2)), no? Info on the default behavior here would be nice. -nathan