[PHP-BUG] Bug #61924 [NEW]: cannot use self in interface function declaration
From: Operating system: PHP version: 5.4.1 Package: Class/Object related Bug Type: Bug Bug description:cannot use self in interface function declaration Description: I am reviewing existing code on a PHP5.4.1 testbed. I've discovered that interface declarations using 'self' as a type hint no longer allow implementations to use 'self' but require them to use the interface name. It is no longer possible for an interface to declare a method that requires the implementor's class as a typehint without declaring that class specifically. And that would limit the usefulness of that interface to one class only. Test script: --- interface IComparable { public function equals(self $other); } class A implements IComparable{ protected $var; public function __construct(self $v){ $this->var=$v; } public function equals($other){ return ($this->var == $other->var) ? 'equal' : 'different'; } } $a1= new A(7); $a2= new A(5); $a3= new A(5); echo $a1->equals($a2),"\n"; echo $a2->equals($a3),"\n"; Expected result: different equal Actual result: -- PHP Fatal error: Declaration of A::equals() must be compatible with IComparable::equals(IComparable $other) -- Edit bug report at https://bugs.php.net/bug.php?id=61924&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61924&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61924&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61924&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61924&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61924&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61924&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61924&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61924&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61924&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61924&r=support Expected behavior: https://bugs.php.net/fix.php?id=61924&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61924&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61924&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61924&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61924&r=php4 Daylight Savings:https://bugs.php.net/fix.php?id=61924&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61924&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61924&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61924&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61924&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61924&r=mysqlcfg
Bug #61924 [Com]: cannot use self in interface function declaration
Edit report at https://bugs.php.net/bug.php?id=61924&edit=1 ID: 61924 Comment by: jenwelsh at yahoo dot com Reported by:jenwelsh at yahoo dot com Summary:cannot use self in interface function declaration Status: Feedback Type: Bug Package:Class/Object related PHP Version:5.4.1 Block user comment: N Private report: N New Comment: The reason I "think" it did work, is because it is **currently** working on a production site with PHP 5.3.11. And it **has** been working for over 2 years. Previous Comments: [2012-05-03 14:52:08] larue...@php.net or you can change it to a feature request :) [2012-05-03 14:45:32] larue...@php.net it's always not allowed since php 5.2, why are you thinking it worked once? [2012-05-03 14:20:54] jenwelsh at yahoo dot com Description: I am reviewing existing code on a PHP5.4.1 testbed. I've discovered that interface declarations using 'self' as a type hint no longer allow implementations to use 'self' but require them to use the interface name. It is no longer possible for an interface to declare a method that requires the implementor's class as a typehint without declaring that class specifically. And that would limit the usefulness of that interface to one class only. Test script: --- interface IComparable { public function equals(self $other); } class A implements IComparable{ protected $var; public function __construct(self $v){ $this->var=$v; } public function equals($other){ return ($this->var == $other->var) ? 'equal' : 'different'; } } $a1= new A(7); $a2= new A(5); $a3= new A(5); echo $a1->equals($a2),"\n"; echo $a2->equals($a3),"\n"; Expected result: different equal Actual result: -- PHP Fatal error: Declaration of A::equals() must be compatible with IComparable::equals(IComparable $other) -- Edit this bug report at https://bugs.php.net/bug.php?id=61924&edit=1
Bug #61924 [Nab]: cannot use self in interface function declaration
Edit report at https://bugs.php.net/bug.php?id=61924&edit=1 ID: 61924 User updated by:jenwelsh at yahoo dot com Reported by:jenwelsh at yahoo dot com Summary:cannot use self in interface function declaration Status: Not a bug Type: Bug Package:Class/Object related PHP Version:5.4.1 Assigned To:laruence Block user comment: N Private report: N New Comment: I am in the unfortunate situation of agreeing that you are technically correct. But I must say that it makes using "self" as a typehint fairly useless in an interface. Now if I want to require that a method argument be same type as $this, I'll have to do it this way: interface IComparable { public function equals($other); } class A implements IComparable{ protected $var; function equals($other) { if(get_class($other)!== get_class($this)) throw Exception('wrong arg class'); return $this->var==$other->var; } } And that will make the interface much less specific and strong. Previous Comments: [2012-05-04 02:24:55] col...@php.net Just to make it clear, you can use self/parent as type hints, as long as the class they reference is right, for instance: class A { public function foo(self $plop) { } } class B extends A { public function foo(A $plop) { } } class C extends A { public function foo(parent $plop) { } } are all equally fine. since parent in C is A, and self in A is A. [2012-05-04 02:18:34] col...@php.net The rule was previously accepted as the type hints where simple syntactic check (basically string comparisons). This was wrong, and got fixed in 5.4. You cannot use self/parent as type hints as they depend on the current type in a covariant fashion, and type hints need to be contravariant. To explicit the problem in 5.3: interface A { public function foo(self $a); } class B implements A { public function foo(self $a) { } } class C implements A { public function foo(self $a) { } } If B (and C) are valid (per foo(new C); } test(new B) will fail test(new C) will work A side effect from this fix is that the wrong typehint now fails with an error, since B/C are invalid implementations of A. [2012-05-04 00:48:01] larue...@php.net Actually, I think it's a improvement of PHP-5.4, this change is introduced by fixing this issue: https://bugs.php.net/bug.php?id=60573 before this, you declare class A implements IComparable{ public function equals(self $other){ return ($this->var == $other->var) ? 'equal' : 'different'; } } actullay the self in here is A, not IComparable. but in the IComparable, the self means IComparable itsself. In scrupulously, A is_a Icomparable, but not equal to Icomperable, what do you think? thanks [2012-05-03 16:48:08] larue...@php.net Oh, sorry I misunderstanded , assign to my self , should have Sth to do with a fix made by me ---------------- [2012-05-03 15:22:17] jenwelsh at yahoo dot com The reason I "think" it did work, is because it is **currently** working on a production site with PHP 5.3.11. And it **has** been working for over 2 years. The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=61924 -- Edit this bug report at https://bugs.php.net/bug.php?id=61924&edit=1
#49778 [NEW]: DateInterval::format("%a") is always zero
From: jenwelsh at yahoo dot com Operating system: Solaris 10 PHP version: 5.3.0 PHP Bug Type: Date/time related Bug description: DateInterval::format("%a") is always zero Description: DateInterval cannot output the total days. It always outputs 0. Reproduce code: --- --- >From manual page: dateinterval.format#Return Values --- $i=new DateInterval('P7D'); print_r($i); echo $i->format("%d"); echo $i->format("%a"); Expected result: DateInterval Object ( [y] => 0 [m] => 0 [d] => 7 [h] => 0 [i] => 0 [s] => 0 [invert] => 0 [days] => 0 ) 7 7 Actual result: -- DateInterval Object ( [y] => 0 [m] => 0 [d] => 7 [h] => 0 [i] => 0 [s] => 0 [invert] => 0 [days] => 0 ) 7 0 -- Edit bug report at http://bugs.php.net/?id=49778&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49778&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49778&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49778&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49778&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49778&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49778&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49778&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49778&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49778&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49778&r=support Expected behavior: http://bugs.php.net/fix.php?id=49778&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49778&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49778&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49778&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49778&r=php4 Daylight Savings:http://bugs.php.net/fix.php?id=49778&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49778&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49778&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49778&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49778&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49778&r=mysqlcfg
#49778 [Opn]: DateInterval::format("%a") is always zero
ID: 49778 User updated by: jenwelsh at yahoo dot com Reported By: jenwelsh at yahoo dot com Status: Open Bug Type: Date/time related Operating System: Solaris 10 PHP Version: 5.3.0 New Comment: DateInterval::format with %a format does work if the DateInterval is the result of getting the difference between two DateTime objects: $d1=date_create('2009-11-02'); $d2=date_create('2009-11-09'); $i=$d2->diff($d1); echo $i->format("%d");//7 echo $i->format("%a");//7 Previous Comments: ---------------- [2009-10-05 14:32:08] jenwelsh at yahoo dot com Description: DateInterval cannot output the total days. It always outputs 0. Reproduce code: --- --- >From manual page: dateinterval.format#Return Values --- $i=new DateInterval('P7D'); print_r($i); echo $i->format("%d"); echo $i->format("%a"); Expected result: DateInterval Object ( [y] => 0 [m] => 0 [d] => 7 [h] => 0 [i] => 0 [s] => 0 [invert] => 0 [days] => 0 ) 7 7 Actual result: -- DateInterval Object ( [y] => 0 [m] => 0 [d] => 7 [h] => 0 [i] => 0 [s] => 0 [invert] => 0 [days] => 0 ) 7 0 -- Edit this bug report at http://bugs.php.net/?id=49778&edit=1