Re: [PHP-CVS] com karma: Use author/email format that can be copied and pasted for use in e-mail clients.: lib/Git/PostReceiveHook.php
Hi: On 20 Mar 2012, at 10:05, Derick Rethans wrote: Commit: f05ac19fc6481815958655f483ef8d0d4fbc3bbe Author: Derick Rethans(git...@derickrethans.nl) Tue, 20 Mar 2012 08:57:53 + Committer: Derick Rethans(git...@derickrethans.nl) Tue, 20 Mar 2012 09:05:42 + Parents: 20a4cccd338af8b1e20ceae4339e563907b4195c Link: http://git.php.net/?p=karma.git;a=commitdiff;h=f05ac19fc6481815958655f483ef8d0d4fbc3bbe Log: Use author/email format that can be copied and pasted for use in e-mail clients. While you guys are doing all these nice little improvements, would it be possible to fold the author and committer line if the authors match? (to be less verbose) And, in the push emails, could the line with the short log go first in every block? That seems to be the most important information in there to me. Here I was also wondering whether the commit hash could be left out to reduce verbosity even more. It is still included in the link. Thanks Stefan -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/NEWS branches/PHP_5_4/Zend/tests/traits/bug60717.phpt branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt branches/PHP_5_4/Zend/zend_compile.c
gron Sun, 04 Mar 2012 18:26:11 + Revision: http://svn.php.net/viewvc?view=revisionrevision=323891 Log: Fixed Bug #60717 (Order of traits in use statement can cause a fatal error) # Compatibility is now correctly checked in both directions. # Introduced helper method for the test. Bug: https://bugs.php.net/60717 (Assigned) Order of traits in use statement can cause a fatal error Changed paths: U php/php-src/branches/PHP_5_4/NEWS A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60717.phpt U php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bug60717.phpt U php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods06.phpt U php/php-src/trunk/Zend/zend_compile.c Modified: php/php-src/branches/PHP_5_4/NEWS === --- php/php-src/branches/PHP_5_4/NEWS 2012-03-04 17:21:16 UTC (rev 323890) +++ php/php-src/branches/PHP_5_4/NEWS 2012-03-04 18:26:11 UTC (rev 323891) @@ -14,6 +14,8 @@ - Core: . Fixed bug #60573 (type hinting with self keyword causes weird errors). (Laruence) + . Fixed bug #60717 (Order of traits in use statement can cause a fatal +error). (Stefan) . Fixed bug #60801 (strpbrk() mishandles NUL byte). (Adam) . Fixed bug #60978 (exit code incorrect). (Laruence) . Fixed bug #61000 (Exceeding max nesting level doesn't delete numerical Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60717.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60717.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60717.phpt 2012-03-04 18:26:11 UTC (rev 323891) @@ -0,0 +1,73 @@ +--TEST-- +Bug #60717 (Order of traits in use statement can cause unexpected unresolved abstract method) +--FILE-- +?php + +namespace HTML +{ + interface Helper + { + function text($text); + function attributes(array $attributes = null); + function textArea(array $attributes = null, $value); + } + + trait TextUTF8 + { + function text($text) {} + } + + trait TextArea + { + function textArea(array $attributes = null, $value) {} + abstract function attributes(array $attributes = null); + abstract function text($text); + } + + trait HTMLAttributes + { + function attributes(array $attributes = null) { } + abstract function text($text); + } + + class HTMLHelper implements Helper + { + use TextArea, HTMLAttributes, TextUTF8; + } + + class HTMLHelper2 implements Helper + { + use TextArea, TextUTF8, HTMLAttributes; + } + + class HTMLHelper3 implements Helper + { + use HTMLAttributes, TextArea, TextUTF8; + } + + class HTMLHelper4 implements Helper + { + use HTMLAttributes, TextUTF8, TextArea; + } + + class HTMLHelper5 implements Helper + { + use TextUTF8, TextArea, HTMLAttributes; + } + + class HTMLHelper6 implements Helper + { + use TextUTF8, HTMLAttributes, TextArea; + } + + $o = new HTMLHelper; +$o = new HTMLHelper2; +$o = new HTMLHelper3; +$o = new HTMLHelper4; +$o = new HTMLHelper5; +$o = new HTMLHelper6; +echo 'Done'; +} + +--EXPECT-- +Done Modified: php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt 2012-03-04 17:21:16 UTC (rev 323890) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt 2012-03-04 18:26:11 UTC (rev 323891) @@ -23,4 +23,4 @@ ? --EXPECTF-- -Fatal error: Declaration of THelloB::hello() must be compatible with THelloA::hello($a) in %s on line %d \ No newline at end of file +Fatal error: Declaration of THelloA::hello($a) must be compatible with THelloB::hello() in %s on line %d \ No newline at end of file Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2012-03-04 17:21:16 UTC (rev 323890) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2012-03-04 18:26:11 UTC (rev 323891) @@ -3623,6 +3623,18 @@ } /* }}} */ +static zend_bool zend_traits_method_compatibility_check(zend_function *fn, zend_function *other_fn TSRMLS_DC) /* {{{ */ +{ + zend_uintfn_flags = fn-common.scope-ce_flags; + zend_uint other_flags = other_fn-common.scope-ce_flags; + + return zend_do_perform_implementation_check(fn, other_fn TSRMLS_CC) + zend_do_perform_implementation_check(other_fn, fn TSRMLS_CC) + ((fn_flags ZEND_ACC_FINAL) == (other_flags ZEND_ACC_FINAL)) /* equal final qualifier */ + ((fn_flags ZEND_ACC_STATIC)== (other_flags ZEND_ACC_STATIC)); /* equal static qualifier */ +} +/* }}} */ + static int zend_traits_merge_functions(zend_function *fn TSRMLS_DC, int
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/NEWS branches/PHP_5_4/Zend/tests/traits/bug55524.phpt branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/tests/traits/bug55524.phpt trunk/Zend/zend_compile.c
gron Sun, 04 Mar 2012 18:33:33 + Revision: http://svn.php.net/viewvc?view=revisionrevision=323892 Log: Fixed Bug #60911 (Confusing error message when extending traits) Bug: https://bugs.php.net/60911 (Assigned) Confusing error message when extending traits Changed paths: U php/php-src/branches/PHP_5_4/NEWS U php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55524.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c U php/php-src/trunk/Zend/tests/traits/bug55524.phpt U php/php-src/trunk/Zend/zend_compile.c Modified: php/php-src/branches/PHP_5_4/NEWS === --- php/php-src/branches/PHP_5_4/NEWS 2012-03-04 18:26:11 UTC (rev 323891) +++ php/php-src/branches/PHP_5_4/NEWS 2012-03-04 18:33:33 UTC (rev 323892) @@ -17,6 +17,7 @@ . Fixed bug #60717 (Order of traits in use statement can cause a fatal error). (Stefan) . Fixed bug #60801 (strpbrk() mishandles NUL byte). (Adam) + . Fixed bug #60911 (Confusing error message when extending traits). (Stefan) . Fixed bug #60978 (exit code incorrect). (Laruence) . Fixed bug #61000 (Exceeding max nesting level doesn't delete numerical vars). (Laruence) Modified: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55524.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55524.phpt 2012-03-04 18:26:11 UTC (rev 323891) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55524.phpt 2012-03-04 18:33:33 UTC (rev 323892) @@ -12,4 +12,4 @@ echo 'DONE'; ? --EXPECTF-- -Fatal error: A trait (Foo) cannot extend a class in %s on line %d +Fatal error: A trait (Foo) cannot extend a class. Traits can only be composed from other traits with the 'use' keyword. Error in %s on line %d Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2012-03-04 18:26:11 UTC (rev 323891) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2012-03-04 18:33:33 UTC (rev 323892) @@ -4995,7 +4995,7 @@ if (doing_inheritance) { /* Make sure a trait does not try to extend a class */ if ((new_class_entry-ce_flags ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) { - zend_error(E_COMPILE_ERROR, A trait (%s) cannot extend a class, new_class_entry-name); + zend_error(E_COMPILE_ERROR, A trait (%s) cannot extend a class. Traits can only be composed from other traits with the 'use' keyword. Error, new_class_entry-name); } opline-extended_value = parent_class_name-u.op.var; Modified: php/php-src/trunk/Zend/tests/traits/bug55524.phpt === --- php/php-src/trunk/Zend/tests/traits/bug55524.phpt 2012-03-04 18:26:11 UTC (rev 323891) +++ php/php-src/trunk/Zend/tests/traits/bug55524.phpt 2012-03-04 18:33:33 UTC (rev 323892) @@ -12,4 +12,4 @@ echo 'DONE'; ? --EXPECTF-- -Fatal error: A trait (Foo) cannot extend a class in %s on line %d +Fatal error: A trait (Foo) cannot extend a class. Traits can only be composed from other traits with the 'use' keyword. Error in %s on line %d Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2012-03-04 18:26:11 UTC (rev 323891) +++ php/php-src/trunk/Zend/zend_compile.c 2012-03-04 18:33:33 UTC (rev 323892) @@ -4995,7 +4995,7 @@ if (doing_inheritance) { /* Make sure a trait does not try to extend a class */ if ((new_class_entry-ce_flags ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) { - zend_error(E_COMPILE_ERROR, A trait (%s) cannot extend a class, new_class_entry-name); + zend_error(E_COMPILE_ERROR, A trait (%s) cannot extend a class. Traits can only be composed from other traits with the 'use' keyword. Error, new_class_entry-name); } opline-extended_value = parent_class_name-u.op.var; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/NEWS branches/PHP_5_4/Zend/tests/traits/bug61052.phpt branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/tests/traits/bug61052.phpt trunk/Zend/zend_compile.c
gron Sun, 04 Mar 2012 19:34:19 + Revision: http://svn.php.net/viewvc?view=revisionrevision=323898 Log: Fixed Bug #61052 (Missing error check in trait 'insteadof' clause) Bug: https://bugs.php.net/61052 (Assigned) missing error check in trait 'insteadof' clause Changed paths: U php/php-src/branches/PHP_5_4/NEWS A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug61052.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bug61052.phpt U php/php-src/trunk/Zend/zend_compile.c Modified: php/php-src/branches/PHP_5_4/NEWS === --- php/php-src/branches/PHP_5_4/NEWS 2012-03-04 19:30:01 UTC (rev 323897) +++ php/php-src/branches/PHP_5_4/NEWS 2012-03-04 19:34:19 UTC (rev 323898) @@ -23,6 +23,7 @@ vars). (Laruence) . Fixed bug #61011 (Crash when an exception is thrown by __autoload accessing a static property). (Laruence) + . Fixed bug #61052 (Missing error check in trait 'insteadof' clause). (Stefan) . Fixed bug #61072 (Memory leak when restoring an exception handler). (Nikic, Laruence) . Fixed bug #61087 (Memory leak in parse_ini_file when specifying Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug61052.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug61052.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug61052.phpt 2012-03-04 19:34:19 UTC (rev 323898) @@ -0,0 +1,18 @@ +--TEST-- +Bug #61052 (missing error check in trait 'insteadof' clause) +--FILE-- +?php +trait T1 { + function foo(){ echo T1\n; } +} +trait T2 { + function foo(){ echo T2\n; } +} +class C { + use T1, T2 { +T1::foo insteadof T1; + } +} +C::foo(); +--EXPECTF-- +Fatal error: Inconsistent insteadof definition. The method foo is to be used from T1, but T1 is also on the exclude list in %s on line %d Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2012-03-04 19:30:01 UTC (rev 323897) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2012-03-04 19:34:19 UTC (rev 323898) @@ -3984,13 +3984,28 @@ /** With the other traits, we are more permissive. We do not give errors for those. This allows to be more - defensive in such definitions. */ + defensive in such definitions. + However, we want to make sure that the insteadof declartion + is consistent in itself. +*/ j = 0; while (cur_precedence-exclude_from_classes[j]) { char* class_name = (char*)cur_precedence-exclude_from_classes[j]; zend_uint name_length = strlen(class_name); cur_precedence-exclude_from_classes[j] = zend_fetch_class(class_name, name_length, ZEND_FETCH_CLASS_TRAIT TSRMLS_CC); + + /* make sure that the trait method is not from a class mentioned in +exclude_from_classes, for consistency */ + if (cur_precedence-trait_method-ce == cur_precedence-exclude_from_classes[i]) { + zend_error(E_COMPILE_ERROR, + Inconsistent insteadof definition. + The method %s is to be used from %s, but %s is also on the exclude list, + cur_method_ref-method_name, + cur_precedence-trait_method-ce-name, + cur_precedence-trait_method-ce-name); + } + efree(class_name); j++; } Added: php/php-src/trunk/Zend/tests/traits/bug61052.phpt === --- php/php-src/trunk/Zend/tests/traits/bug61052.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bug61052.phpt 2012-03-04 19:34:19 UTC (rev 323898) @@ -0,0 +1,18 @@ +--TEST-- +Bug #61052 (missing error check in trait 'insteadof' clause) +--FILE-- +?php +trait T1 { + function foo(){ echo T1\n; } +} +trait T2 { +
Re: [PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/NEWS branches/PHP_5_4/Zend/zend_compile.c branches/PHP_5_4/Zend/zend_object_handlers.c trunk/Zend/zend_compile.c trunk/Zend/zend_object_handlers.c
Hi: Thanks guys! I have only briefly rechecked the code, and dont remember at the moment how the default property table works, but for me it feels like these offsets are also incorrect for public or protected stuff that gets newly added to the class? Best regards Stefan On 19 Dec 2011, at 17:48, Xinchen Hui wrote: laruence Mon, 19 Dec 2011 16:48:18 + Revision: http://svn.php.net/viewvc?view=revisionrevision=321166 Log: Fixed bug #60558 (Invalid read and writes) Re-Fixed bug #60536 (Traits Segfault) #Thanks to tony2001, I found the previous fix -r321089 is actually not a correct one. #The key problem there is because the traits didn't correct set the property_info.offset #for private properties. so here come the new fix. Bugs: https://bugs.php.net/60558 (Re-Opened) Invalid read and writes https://bugs.php.net/60536 (Closed) Traits Segfault Changed paths: U php/php-src/branches/PHP_5_4/NEWS U php/php-src/branches/PHP_5_4/Zend/zend_compile.c U php/php-src/branches/PHP_5_4/Zend/zend_object_handlers.c U php/php-src/trunk/Zend/zend_compile.c U php/php-src/trunk/Zend/zend_object_handlers.c svn-diffs-321166.txt-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/bug60536_001.phpt branches/PHP_5_4/Zend/tests/bug60536_003.phpt branches/PHP_5_4/Zend/tests/bug60536_004.phpt branches/PHP_5_4/Zend/tests/trait
gron Sat, 17 Dec 2011 14:26:39 + Revision: http://svn.php.net/viewvc?view=revisionrevision=321089 Log: Fixed inconsistent and broken handling of private properties in traits. # The handling of private properties in classes is now consistent with private properties in traits. # Perviously, privates could cause strict warnings, are were not properly merged into the class when # the parent class had a private property of the same name. Now, we introduce it without notice, # since it is a new and independent property, just like in normal classes. # This problem was diagnosed while working on Bug #60536. Bug: https://bugs.php.net/60536 (Closed) Traits Segfault Changed paths: U php/php-src/branches/PHP_5_4/Zend/tests/bug60536_001.phpt U php/php-src/branches/PHP_5_4/Zend/tests/bug60536_003.phpt U php/php-src/branches/PHP_5_4/Zend/tests/bug60536_004.phpt U php/php-src/branches/PHP_5_4/Zend/tests/traits/property005.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/property006.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/property007.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/property008.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/property009.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c U php/php-src/trunk/Zend/tests/bug60536_001.phpt U php/php-src/trunk/Zend/tests/bug60536_003.phpt U php/php-src/trunk/Zend/tests/bug60536_004.phpt U php/php-src/trunk/Zend/tests/traits/property005.phpt A php/php-src/trunk/Zend/tests/traits/property006.phpt A php/php-src/trunk/Zend/tests/traits/property007.phpt A php/php-src/trunk/Zend/tests/traits/property008.phpt A php/php-src/trunk/Zend/tests/traits/property009.phpt U php/php-src/trunk/Zend/zend_compile.c Modified: php/php-src/branches/PHP_5_4/Zend/tests/bug60536_001.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/bug60536_001.phpt 2011-12-17 13:29:49 UTC (rev 321088) +++ php/php-src/branches/PHP_5_4/Zend/tests/bug60536_001.phpt 2011-12-17 14:26:39 UTC (rev 321089) @@ -22,5 +22,4 @@ echo DONE; ? --EXPECTF-- -Strict Standards: X and T define the same property ($x) in the composition of Y. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %sbug60536_001.php on line %d DONE Modified: php/php-src/branches/PHP_5_4/Zend/tests/bug60536_003.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/bug60536_003.phpt 2011-12-17 13:29:49 UTC (rev 321088) +++ php/php-src/branches/PHP_5_4/Zend/tests/bug60536_003.phpt 2011-12-17 14:26:39 UTC (rev 321089) @@ -1,5 +1,5 @@ --TEST-- -Private (relevant to #60536) +Properties should be initialized correctly (relevant to #60536) --FILE-- ?php error_reporting(E_ALL | E_STRICT); @@ -32,9 +32,6 @@ ? --EXPECTF-- -Strict Standards: BaseWithPropA and AHelloProperty define the same property ($hello) in the composition of SubclassA. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %sbug60536_003.php on line %d - -Strict Standards: BaseWithTPropB and AHelloProperty define the same property ($hello) in the composition of SubclassB. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %sbug60536_003.php on line %d object(SubclassA)#%d (2) { [hello:SubclassA:private]= int(0) Modified: php/php-src/branches/PHP_5_4/Zend/tests/bug60536_004.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/bug60536_004.phpt 2011-12-17 13:29:49 UTC (rev 321088) +++ php/php-src/branches/PHP_5_4/Zend/tests/bug60536_004.phpt 2011-12-17 14:26:39 UTC (rev 321089) @@ -31,8 +31,6 @@ ? --EXPECTF-- PRE-CLASS-GUARD - -Strict Standards: Base and THello1 define the same property ($hello) in the composition of SameNameInSubClassNoNotice. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %sbug60536_004.php on line %d POST-CLASS-GUARD Strict Standards: Notice and THello1 define the same property ($hello) in the composition of Notice. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %sbug60536_004.php on line %d Modified: php/php-src/branches/PHP_5_4/Zend/tests/traits/property005.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/property005.phpt 2011-12-17 13:29:49 UTC (rev 321088) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/property005.phpt 2011-12-17 14:26:39 UTC (rev 321089) @@ -13,18 +13,11 @@ } echo
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bug60369.phpt branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/tests/traits/bug60369.phpt trunk/Zend/zend_compile.c
gron Wed, 23 Nov 2011 21:24:34 + Revision: http://svn.php.net/viewvc?view=revisionrevision=319727 Log: Fixed Bug #60369Crash with static property in trait Bug: https://bugs.php.net/60369 (Verified) Crash with static property in trait Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60369.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bug60369.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60369.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60369.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60369.phpt 2011-11-23 21:24:34 UTC (rev 319727) @@ -0,0 +1,17 @@ +--TEST-- +Bug #60369 (Crash with static property in trait) +--FILE-- +?php + +trait PropertiesTrait { + static $same = true; +} + +class Properties { + use PropertiesTrait; + public $same = true; +} + +? +--EXPECTF-- +Fatal error: Properties and PropertiesTrait define the same property ($same) in the composition of Properties. However, the definition differs and is considered incompatible. Class was composed in %s on line %d \ No newline at end of file Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-11-23 21:21:10 UTC (rev 319726) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-11-23 21:24:34 UTC (rev 319727) @@ -4272,10 +4272,11 @@ /* this one is inherited, lets look it up in its own class */ zend_hash_quick_find(coliding_prop-ce-properties_info, prop_name, prop_name_length+1, prop_hash, (void **) coliding_prop); } - if ((coliding_prop-flags ZEND_ACC_PPP_MASK) == (property_info-flags ZEND_ACC_PPP_MASK)) { + if ( (coliding_prop-flags (ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC)) + == (property_info-flags (ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC))) { /* flags are identical, now the value needs to be checked */ if (property_info-flags ZEND_ACC_STATIC) { -not_compatible = (FAILURE == compare_function(compare_result, + not_compatible = (FAILURE == compare_function(compare_result, ce-default_static_members_table[coliding_prop-offset], ce-traits[i]-default_static_members_table[property_info-offset] TSRMLS_CC)) || (Z_LVAL(compare_result) != 0); Added: php/php-src/trunk/Zend/tests/traits/bug60369.phpt === --- php/php-src/trunk/Zend/tests/traits/bug60369.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bug60369.phpt 2011-11-23 21:24:34 UTC (rev 319727) @@ -0,0 +1,17 @@ +--TEST-- +Bug #60369 (Crash with static property in trait) +--FILE-- +?php + +trait PropertiesTrait { + static $same = true; +} + +class Properties { + use PropertiesTrait; + public $same = true; +} + +? +--EXPECTF-- +Fatal error: Properties and PropertiesTrait define the same property ($same) in the composition of Properties. However, the definition differs and is considered incompatible. Class was composed in %s on line %d \ No newline at end of file Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2011-11-23 21:21:10 UTC (rev 319726) +++ php/php-src/trunk/Zend/zend_compile.c 2011-11-23 21:24:34 UTC (rev 319727) @@ -4272,10 +4272,11 @@ /* this one is inherited, lets look it up in its own class */ zend_hash_quick_find(coliding_prop-ce-properties_info, prop_name, prop_name_length+1, prop_hash, (void **) coliding_prop); } - if ((coliding_prop-flags ZEND_ACC_PPP_MASK) == (property_info-flags ZEND_ACC_PPP_MASK)) { + if ( (coliding_prop-flags (ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC)) + == (property_info-flags (ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC))) { /* flags are identical, now the value needs to be checked */ if (property_info-flags ZEND_ACC_STATIC) { -not_compatible = (FAILURE ==
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bug54441.phpt branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/tests/traits/bug54441.phpt trunk/Zend/zend_compile.c
gron Fri, 18 Nov 2011 13:49:07 + Revision: http://svn.php.net/viewvc?view=revisionrevision=319483 Log: Fixes Bug #54441 (Handling of changing modifiers on a trait alias) # this now results also in a compilation error, since it would open the door for inconsistencies, and violates the DRY principle. Bug: https://bugs.php.net/54441 (Assigned) Traits - Visibility on alias names Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug54441.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bug54441.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug54441.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug54441.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug54441.phpt 2011-11-18 13:49:07 UTC (rev 319483) @@ -0,0 +1,19 @@ +--TEST-- +Bug #54441 (Changing trait static method visibility) +--FILE-- +?php + +trait Foo { + public function bar() {} +} + +class Boo { + use Foo { +bar as dontKnow; +dontKnow as protected; + } +} + +? +--EXPECTF-- +Fatal error: The modifiers for the trait alias dontKnow() need to be changed in the same statment in which the alias is defined. Error in %s on line %d Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-11-18 13:46:39 UTC (rev 319482) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-11-18 13:49:07 UTC (rev 319483) @@ -4320,16 +4320,49 @@ static void zend_do_check_for_inconsistent_traits_aliasing(zend_class_entry *ce TSRMLS_DC) /* {{{ */ { int i = 0; + zend_trait_alias* cur_alias; + char* lc_method_name; if (ce-trait_aliases) { while (ce-trait_aliases[i]) { + cur_alias = ce-trait_aliases[i]; /** The trait for this alias has not been resolved, this means, this alias was not applied. Abort with an error. */ - if (!ce-trait_aliases[i]-trait_method-ce) { - zend_error(E_COMPILE_ERROR, - An alias (%s) was defined for method %s(), but this method does not exist, - ce-trait_aliases[i]-alias, - ce-trait_aliases[i]-trait_method-method_name); + if (!cur_alias-trait_method-ce) { + if (cur_alias-alias) { + /** Plain old inconsistency/typo/bug */ + zend_error(E_COMPILE_ERROR, + An alias (%s) was defined for method %s(), but this method does not exist, + cur_alias-alias, + cur_alias-trait_method-method_name); + } + else { + /** Here are two possible cases: + 1) this is an attempt to modifiy the visibility + of a method introduce as part of another alias. + Since that seems to violate the DRY principle, + we check against it and abort. + 2) it is just a plain old inconsitency/typo/bug + as in the case where alias is set. */ + + lc_method_name = zend_str_tolower_dup(cur_alias-trait_method-method_name, + cur_alias-trait_method-mname_len); + if (zend_hash_exists(ce-function_table, + lc_method_name, + cur_alias-trait_method-mname_len+1)) { + efree(lc_method_name); + zend_error(E_COMPILE_ERROR, + The modifiers for the trait alias %s() need to be changed in the same statment in which the alias is defined. Error, + cur_alias-trait_method-method_name); +
Re: [PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/zend_compile.c
Hi Felipe: On 18 Nov 2011, at 14:56, Felipe Pena wrote: felipe Fri, 18 Nov 2011 13:56:41 + Revision: http://svn.php.net/viewvc?view=revisionrevision=319487 - else if (!strncmp(mname, ZEND_DESTRUCTOR_FUNC_NAME, mname_len)) { ce-destructor = fe; fe-common.fn_flags |= ZEND_ACC_DTOR; } - else if (!strncmp(mname, ZEND_GET_FUNC_NAME, mname_len)) ce-__get = fe; - else if (!strncmp(mname, ZEND_SET_FUNC_NAME, mname_len)) ce-__set = fe; - else if (!strncmp(mname, ZEND_CALL_FUNC_NAME,mname_len)) ce-__call = fe; - else if (!strncmp(mname, ZEND_UNSET_FUNC_NAME, mname_len)) ce-__unset = fe; - else if (!strncmp(mname, ZEND_ISSET_FUNC_NAME, mname_len)) ce-__isset = fe; - else if (!strncmp(mname, ZEND_CALLSTATIC_FUNC_NAME, mname_len)) ce-__callstatic= fe; - else if (!strncmp(mname, ZEND_TOSTRING_FUNC_NAME,mname_len)) ce-__tostring = fe; - else if (ce-name_length + 1 == mname_len) { + } else if (!strncmp(mname, ZEND_DESTRUCTOR_FUNC_NAME, mname_len)) { + ce-destructor = fe; fe-common.fn_flags |= ZEND_ACC_DTOR; + } else if (!strncmp(mname, ZEND_GET_FUNC_NAME, mname_len)) { + ce-__get = fe; + } else if (!strncmp(mname, ZEND_SET_FUNC_NAME, mname_len)) { + ce-__set = fe; + } else if (!strncmp(mname, ZEND_CALL_FUNC_NAME, mname_len)) { + ce-__call = fe; + } else if (!strncmp(mname, ZEND_UNSET_FUNC_NAME, mname_len)) { + ce-__unset = fe; + } else if (!strncmp(mname, ZEND_ISSET_FUNC_NAME, mname_len)) { + ce-__isset = fe; + } else if (!strncmp(mname, ZEND_CALLSTATIC_FUNC_NAME, mname_len)) { + ce-__callstatic = fe; + } else if (!strncmp(mname, ZEND_TOSTRING_FUNC_NAME, mname_len)) { + ce-__tostring = fe; + } else if (ce-name_length + 1 == mname_len) { How is that change an improvement for readability? The previous formatting was an implicit tabled arrangement, which makes it very easy to see what the commonalities are and where the code differs. Breaking that up into multiple lines, does IMHO not improve readability or clarity. If you just missed the braces, well, they could have been added inline, no? And I do not really buy that 'CS' (that is coding style?) applies to such a special piece of code. Would it be a problem to revert that change, or at least 'table' it again? Best regards Stefan -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/zend_compile.c
Hi: On 18 Nov 2011, at 15:16, Felipe Pena wrote: Hi, 2011/11/18 Stefan Marr p...@stefan-marr.de: Hi Felipe: On 18 Nov 2011, at 14:56, Felipe Pena wrote: felipe Fri, 18 Nov 2011 13:56:41 + Revision: http://svn.php.net/viewvc?view=revisionrevision=319487 - else if (!strncmp(mname, ZEND_DESTRUCTOR_FUNC_NAME, mname_len)) { ce-destructor = fe; fe-common.fn_flags |= ZEND_ACC_DTOR; } - else if (!strncmp(mname, ZEND_GET_FUNC_NAME, mname_len)) ce-__get = fe; - else if (!strncmp(mname, ZEND_SET_FUNC_NAME, mname_len)) ce-__set = fe; - else if (!strncmp(mname, ZEND_CALL_FUNC_NAME,mname_len)) ce-__call = fe; - else if (!strncmp(mname, ZEND_UNSET_FUNC_NAME, mname_len)) ce-__unset = fe; - else if (!strncmp(mname, ZEND_ISSET_FUNC_NAME, mname_len)) ce-__isset = fe; - else if (!strncmp(mname, ZEND_CALLSTATIC_FUNC_NAME, mname_len)) ce-__callstatic= fe; - else if (!strncmp(mname, ZEND_TOSTRING_FUNC_NAME,mname_len)) ce-__tostring = fe; - else if (ce-name_length + 1 == mname_len) { + } else if (!strncmp(mname, ZEND_DESTRUCTOR_FUNC_NAME, mname_len)) { + ce-destructor = fe; fe-common.fn_flags |= ZEND_ACC_DTOR; + } else if (!strncmp(mname, ZEND_GET_FUNC_NAME, mname_len)) { + ce-__get = fe; + } else if (!strncmp(mname, ZEND_SET_FUNC_NAME, mname_len)) { + ce-__set = fe; + } else if (!strncmp(mname, ZEND_CALL_FUNC_NAME, mname_len)) { + ce-__call = fe; + } else if (!strncmp(mname, ZEND_UNSET_FUNC_NAME, mname_len)) { + ce-__unset = fe; + } else if (!strncmp(mname, ZEND_ISSET_FUNC_NAME, mname_len)) { + ce-__isset = fe; + } else if (!strncmp(mname, ZEND_CALLSTATIC_FUNC_NAME, mname_len)) { + ce-__callstatic = fe; + } else if (!strncmp(mname, ZEND_TOSTRING_FUNC_NAME, mname_len)) { + ce-__tostring = fe; + } else if (ce-name_length + 1 == mname_len) { How is that change an improvement for readability? The previous formatting was an implicit tabled arrangement, which makes it very easy to see what the commonalities are and where the code differs. Breaking that up into multiple lines, does IMHO not improve readability or clarity. If you just missed the braces, well, they could have been added inline, no? And I do not really buy that 'CS' (that is coding style?) applies to such a special piece of code. Would it be a problem to revert that change, or at least 'table' it again? CS = Coding standards Well, our codind standards in the CODING_STANDARDS file states: ---8--- 3. Be generous with whitespace and braces. Keep one empty line between the variable declaration section and the statements in a block, as well as between logical statement groups in a block. Maintain at least one empty line between two functions, preferably two. Always prefer:: if (foo) { bar; } to: if(foo)bar; ---8--- So I just did it in conforming whole rest of the code. It's not a question of readability, but the following an adopted standards. Then at least follow what 3. states as the first (and deducted from that) most important statement: Be generous with whitespace Please, make it look like a table. That is not against the coding standards. (Which IMHO should leave room for exceptions when it comes to readability) Be generous with whitespace! Thanks. Stefan -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/zend_compile.c
On 18 Nov 2011, at 15:36, Felipe Pena wrote: 'Be generous with whitespace' is the opposite of what you want to do. I.e. generous != stingy. :P I was obviously to imprecise in my request: Index: Zend/zend_compile.c === --- Zend/zend_compile.c (revision 319492) +++ Zend/zend_compile.c (working copy) @@ -3815,30 +3815,45 @@ static void zend_add_magic_methods(zend_class_entry* ce, const char* mname, uint mname_len, zend_function* fe TSRMLS_DC) /* {{{ */ { - if (!strncmp(mname, ZEND_CLONE_FUNC_NAME, mname_len)) { - ce-clone = fe; fe-common.fn_flags |= ZEND_ACC_CLONE; - } else if (!strncmp(mname, ZEND_CONSTRUCTOR_FUNC_NAME, mname_len)) { + if (!strncmp(mname, ZEND_CLONE_FUNC_NAME, mname_len)) { + fe-common.fn_flags |= ZEND_ACC_CLONE; + ce-clone = fe; + } + else if (!strncmp(mname,ZEND_CONSTRUCTOR_FUNC_NAME, mname_len)) { + fe-common.fn_flags |= ZEND_ACC_CTOR; if (ce-constructor) { - zend_error(E_COMPILE_ERROR, %s has colliding constructor definitions coming from traits, ce-name); + zend_error(E_COMPILE_ERROR, + %s has colliding constructor definitions coming from traits, + ce-name); } - ce-constructor = fe; fe-common.fn_flags |= ZEND_ACC_CTOR; - } else if (!strncmp(mname, ZEND_DESTRUCTOR_FUNC_NAME, mname_len)) { - ce-destructor = fe; fe-common.fn_flags |= ZEND_ACC_DTOR; - } else if (!strncmp(mname, ZEND_GET_FUNC_NAME, mname_len)) { - ce-__get = fe; - } else if (!strncmp(mname, ZEND_SET_FUNC_NAME, mname_len)) { - ce-__set = fe; - } else if (!strncmp(mname, ZEND_CALL_FUNC_NAME, mname_len)) { - ce-__call = fe; - } else if (!strncmp(mname, ZEND_UNSET_FUNC_NAME, mname_len)) { - ce-__unset = fe; - } else if (!strncmp(mname, ZEND_ISSET_FUNC_NAME, mname_len)) { - ce-__isset = fe; - } else if (!strncmp(mname, ZEND_CALLSTATIC_FUNC_NAME, mname_len)) { - ce-__callstatic = fe; - } else if (!strncmp(mname, ZEND_TOSTRING_FUNC_NAME, mname_len)) { - ce-__tostring = fe; - } else if (ce-name_length + 1 == mname_len) { + ce-constructor = fe; + } + else if (!strncmp(mname,ZEND_DESTRUCTOR_FUNC_NAME, mname_len)) { + fe-common.fn_flags |= ZEND_ACC_DTOR; + ce-destructor = fe; + } + else if (!strncmp(mname,ZEND_GET_FUNC_NAME, mname_len)) { + ce-__get = fe; + } + else if (!strncmp(mname,ZEND_SET_FUNC_NAME, mname_len)) { + ce-__set = fe; + } + else if (!strncmp(mname,ZEND_CALL_FUNC_NAME, mname_len)) { + ce-__call = fe; + } + else if (!strncmp(mname,ZEND_UNSET_FUNC_NAME, mname_len)) { + ce-__unset = fe; + } + else if (!strncmp(mname,ZEND_ISSET_FUNC_NAME, mname_len)) { + ce-__isset = fe; + } + else if (!strncmp(mname,ZEND_CALLSTATIC_FUNC_NAME, mname_len)) { + ce-__callstatic= fe; + } + else if (!strncmp(mname,ZEND_TOSTRING_FUNC_NAME, mname_len)) { + ce-__tostring = fe; + } + else if (ce-name_length + 1 == mname_len) { char *lowercase_name = emalloc(ce-name_length + 1); zend_str_tolower_copy(lowercase_name, ce-name, ce-name_length); lowercase_name = (char*)zend_new_interned_string(lowercase_name, ce-name_length + 1, 1 TSRMLS_CC); The only thing you can argue about that is, that `else` is not on the same line as the closing brace of the if. However, you will see, if you remove it, that it becomes hard to parse the code. At least for me. So I would put in the break to emphasize the `else if` condition. Anyway, that is what I mean with `tabling` the related parts. I don't see how that violates the style guide, but IMHO, it makes quite a difference when it comes to readability of such involved if/else if/else if/else if/else if/else if/else if/else if/else if/else if constructs. Best regards Stefan -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bug60165a.phpt branches/PHP_5_4/Zend/tests/traits/bug60165b.phpt branches/PHP_5_4/Zend/tests/traits/bug60165c.phpt branches/PHP_5_4/Zend
gron Thu, 17 Nov 2011 21:04:15 + Revision: http://svn.php.net/viewvc?view=revisionrevision=319420 Log: Fixed Bug #60165 (Aliasing unexisting trait should throw/trigger the exception/error) - aliases that are not actually matching anything are treated as errors now. This will make sure that all methods that are expected to be in a class are actually there, or in case a trait changed for instance, that the code breaks already on composition - Precedence declarations are also checked to ensure that the method which is supposed to take precedence actually exists, however, the other traits mentioned in the declaration are not regarded. We are more lenient here, since this avoids unnecessary fragility. - fixed another seamingly unrelated test which broke in the progress but wasn't clear before either. Bug: https://bugs.php.net/60165 (Assigned) Overriding unexisting trait should throw/trigger the exception/error Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165a.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165b.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165c.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165d.phpt U php/php-src/branches/PHP_5_4/Zend/tests/traits/language011.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bug60165a.phpt A php/php-src/trunk/Zend/tests/traits/bug60165b.phpt A php/php-src/trunk/Zend/tests/traits/bug60165c.phpt A php/php-src/trunk/Zend/tests/traits/bug60165d.phpt U php/php-src/trunk/Zend/tests/traits/language011.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165a.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165a.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165a.phpt 2011-11-17 21:04:15 UTC (rev 319420) @@ -0,0 +1,17 @@ +--TEST-- +Bug #60165 (Aliasing unexisting trait should throw/trigger the exception/error) +--FILE-- +?php + +trait A { +public function bar() {} +} + +class MyClass { +use A { +nonExistent as barA; +} +} + +--EXPECTF-- +Fatal error: An alias (barA) was defined for method nonExistent(), but this method does not exist in %s on line %d Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165b.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165b.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165b.phpt 2011-11-17 21:04:15 UTC (rev 319420) @@ -0,0 +1,17 @@ +--TEST-- +Bug #60165 (Aliasing unexisting trait should throw/trigger the exception/error) +--FILE-- +?php + +trait A { +public function bar() {} +} + +class MyClass { +use A { +A::nonExistent as barA; +} +} + +--EXPECTF-- +Fatal error: An alias was defined for A::nonExistent but this method does not exist in %s on line %d Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165c.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165c.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165c.phpt 2011-11-17 21:04:15 UTC (rev 319420) @@ -0,0 +1,22 @@ +--TEST-- +Bug #60165 (Aliasing unexisting trait should throw/trigger the exception/error) +--FILE-- +?php + +trait A { +public function bar() {} +} + +trait B { +public function foo() {} +} + +class MyClass { +use A, B { +foo as fooB; +baz as foobar; +} +} + +--EXPECTF-- +Fatal error: An alias (foobar) was defined for method baz(), but this method does not exist in %s on line %d Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165d.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165d.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60165d.phpt 2011-11-17 21:04:15 UTC (rev 319420) @@ -0,0 +1,21 @@ +--TEST-- +Bug #60165 (Aliasing unexisting trait should throw/trigger the exception/error) +--FILE-- +?php + +// The same is true for the insteadof operator to resolve conflicts + +trait A {} + +trait B { +public function bar() {} +} + +class MyClass { +use A, B { +A::bar insteadof B; +} +} + +--EXPECTF-- +Fatal error: A precedence rule was defined for A::bar but this method does not exist in %s on line %d Modified: php/php-src/branches/PHP_5_4/Zend/tests/traits/language011.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/language011.phpt 2011-11-17 20:43:56 UTC (rev 319419) +++
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bug60217a.phpt branches/PHP_5_4/Zend/tests/traits/bug60217b.phpt branches/PHP_5_4/Zend/tests/traits/bug60217c.phpt branches/PHP_5_4/Zend
gron Sat, 05 Nov 2011 01:46:40 + Revision: http://svn.php.net/viewvc?view=revisionrevision=318793 Log: Fixed Bug #60217 (Requiring the same method from different traits) - also added test to check for inconsistent abstract method definitions, they need to be compatible Bug: https://bugs.php.net/60217 (Assigned) imposing requirements in traits Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60217a.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60217b.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60217c.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bug60217a.phpt A php/php-src/trunk/Zend/tests/traits/bug60217b.phpt A php/php-src/trunk/Zend/tests/traits/bug60217c.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60217a.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60217a.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60217a.phpt 2011-11-05 01:46:40 UTC (rev 318793) @@ -0,0 +1,26 @@ +--TEST-- +Bug #60217 (Requiring the same method from different traits.) +--FILE-- +?php + +trait T1 { +public abstract function foo(); +} + +trait T2 { +public abstract function foo(); +} + +class C { +use T1, T2; + +public function foo() { +echo C::foo() works.\n; +} +} + +$o = new C; +$o-foo(); + +--EXPECTF-- +C::foo() works. Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60217b.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60217b.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60217b.phpt 2011-11-05 01:46:40 UTC (rev 318793) @@ -0,0 +1,26 @@ +--TEST-- +Bug #60217 (Requiring the same method from different traits and abstract methods have to be compatible) +--FILE-- +?php + +trait TBroken1 { +public abstract function foo($a); +} + +trait TBroken2 { +public abstract function foo($a, $b = 0); +} + +class CBroken { +use TBroken1, TBroken2; + +public function foo($a) { +echo 'FOO'; +} +} + +$o = new CBroken; +$o-foo(1); + +--EXPECTF-- +Fatal error: Declaration of TBroken1::foo($a) must be compatible with TBroken2::foo($a, $b = 0) in %s on line %d Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60217c.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60217c.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60217c.phpt 2011-11-05 01:46:40 UTC (rev 318793) @@ -0,0 +1,26 @@ +--TEST-- +Bug #60217 (Requiring the same method from different traits and abstract methods have to be compatible, in both directions.) +--FILE-- +?php + +trait TBroken1 { +public abstract function foo($a, $b = 0); +} + +trait TBroken2 { +public abstract function foo($a); +} + +class CBroken { +use TBroken1, TBroken2; + +public function foo($a) { +echo 'FOO'; +} +} + +$o = new CBroken; +$o-foo(1); + +--EXPECTF-- +Fatal error: Declaration of TBroken1::foo($a, $b = 0) must be compatible with TBroken2::foo($a) in %s on line %d Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2011-11-04 22:58:44 UTC (rev 318792) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2011-11-05 01:46:40 UTC (rev 318793) @@ -3617,7 +3617,19 @@ /* if it is an abstract method, there is no collision */ if (other_trait_fn-common.fn_flags ZEND_ACC_ABSTRACT) { /* Make sure they are compatible */ -do_inheritance_check_on_method(fn, other_trait_fn TSRMLS_CC); +if (fn-common.fn_flags ZEND_ACC_ABSTRACT) { + /* In case both are abstract, just check prototype, but need to do that in both directions */ + if ( !zend_do_perform_implementation_check(fn, other_trait_fn TSRMLS_CC) + || !zend_do_perform_implementation_check(other_trait_fn, fn TSRMLS_CC)) { +zend_error(E_COMPILE_ERROR, Declaration of %s must be compatible with %s, //ZEND_FN_SCOPE_NAME(fn), fn-common.function_name, //::%s() + zend_get_function_declaration(fn TSRMLS_CC), + zend_get_function_declaration(other_trait_fn TSRMLS_CC)); + } +} +else { + /* otherwise, do the full check */ + do_inheritance_check_on_method(fn, other_trait_fn TSRMLS_CC); +} /* we can savely free and remove it from other table */ zend_function_dtor(other_trait_fn); @@ -3626,7 +3638,8 @@ /* if it is not an abstract method, there is still no collision */ /* if fn is an abstract
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/zend_compile.c
gron Sat, 05 Nov 2011 02:05:28 + Revision: http://svn.php.net/viewvc?view=revisionrevision=318794 Log: Fixed inconsistent whitespace. # Belongs to svn rev. 318793. Changed paths: U php/php-src/branches/PHP_5_4/Zend/zend_compile.c U php/php-src/trunk/Zend/zend_compile.c Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2011-11-05 01:46:40 UTC (rev 318793) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2011-11-05 02:05:28 UTC (rev 318794) @@ -3617,19 +3617,19 @@ /* if it is an abstract method, there is no collision */ if (other_trait_fn-common.fn_flags ZEND_ACC_ABSTRACT) { /* Make sure they are compatible */ -if (fn-common.fn_flags ZEND_ACC_ABSTRACT) { - /* In case both are abstract, just check prototype, but need to do that in both directions */ - if ( !zend_do_perform_implementation_check(fn, other_trait_fn TSRMLS_CC) - || !zend_do_perform_implementation_check(other_trait_fn, fn TSRMLS_CC)) { -zend_error(E_COMPILE_ERROR, Declaration of %s must be compatible with %s, //ZEND_FN_SCOPE_NAME(fn), fn-common.function_name, //::%s() - zend_get_function_declaration(fn TSRMLS_CC), - zend_get_function_declaration(other_trait_fn TSRMLS_CC)); - } -} -else { - /* otherwise, do the full check */ - do_inheritance_check_on_method(fn, other_trait_fn TSRMLS_CC); -} +if (fn-common.fn_flags ZEND_ACC_ABSTRACT) { + /* In case both are abstract, just check prototype, but need to do that in both directions */ + if ( !zend_do_perform_implementation_check(fn, other_trait_fn TSRMLS_CC) + || !zend_do_perform_implementation_check(other_trait_fn, fn TSRMLS_CC)) { + zend_error(E_COMPILE_ERROR, Declaration of %s must be compatible with %s, //ZEND_FN_SCOPE_NAME(fn), fn-common.function_name, //::%s() + zend_get_function_declaration(fn TSRMLS_CC), + zend_get_function_declaration(other_trait_fn TSRMLS_CC)); + } +} +else { + /* otherwise, do the full check */ + do_inheritance_check_on_method(fn, other_trait_fn TSRMLS_CC); +} /* we can savely free and remove it from other table */ zend_function_dtor(other_trait_fn); @@ -3639,7 +3639,7 @@ /* if fn is an abstract method */ if (fn-common.fn_flags ZEND_ACC_ABSTRACT) { /* Make sure they are compatible. - Here, we already know other_trait_fn cannot be abstract, full check ok. */ + Here, we already know other_trait_fn cannot be abstract, full check ok. */ do_inheritance_check_on_method(other_trait_fn, fn TSRMLS_CC); /* just mark as solved, will be added if its own trait is processed */ @@ -3810,7 +3810,7 @@ fe-op_array.try_catch_array = (zend_try_catch_element*)estrndup((char*)fe-op_array.try_catch_array, sizeof(zend_try_catch_element) * fe-op_array.last_try_catch); fe-op_array.brk_cont_array = (zend_brk_cont_element*)estrndup((char*)fe-op_array.brk_cont_array, sizeof(zend_brk_cont_element) * fe-op_array.last_brk_cont); - + } /* }}} */ @@ -3856,7 +3856,7 @@ zend_function* existing_fn = NULL; zend_function fn_copy, *fn_copy_p; zend_function* prototype = NULL; /* is used to determine the prototype according to the inheritance chain */ - + if (zend_hash_quick_find(ce-function_table, hash_key-arKey, hash_key-nKeyLength, hash_key-h, (void**) existing_fn) == FAILURE) { add = 1; /* not found */ } else if (existing_fn-common.scope != ce) { @@ -3869,7 +3869,7 @@ prototype = parent_function; /* -common.fn_flags |= ZEND_ACC_ABSTRACT; */ /* we got that method in the parent class, and are going to override it, - except, if the trait is just asking to have an abstract method implemented. */ + except, if the trait is just asking to have an abstract method implemented. */ if (fn-common.fn_flags ZEND_ACC_ABSTRACT) { /* then we clean up an skip this method */ zend_function_dtor(fn); @@ -3881,14 +3881,14 @@ fn-common.prototype = prototype; if (prototype - (prototype-common.fn_flags ZEND_ACC_IMPLEMENTED_ABSTRACT -|| prototype-common.fn_flags ZEND_ACC_ABSTRACT)) { - fn-common.fn_flags |= ZEND_ACC_IMPLEMENTED_ABSTRACT; -} else if (fn-common.fn_flags ZEND_ACC_IMPLEMENTED_ABSTRACT) { - /* remove ZEND_ACC_IMPLEMENTED_ABSTRACT flag, think it shouldn't be copied to class */ - fn-common.fn_flags = fn-common.fn_flags - ZEND_ACC_IMPLEMENTED_ABSTRACT; -} - + (prototype-common.fn_flags ZEND_ACC_IMPLEMENTED_ABSTRACT +|| prototype-common.fn_flags ZEND_ACC_ABSTRACT)) { +fn-common.fn_flags |= ZEND_ACC_IMPLEMENTED_ABSTRACT; + } else if (fn-common.fn_flags ZEND_ACC_IMPLEMENTED_ABSTRACT) { +/* remove ZEND_ACC_IMPLEMENTED_ABSTRACT
Re: [PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/zend_compile.c
Hi Antony: On 02 Nov 2011, at 22:05, Antony Dovgal wrote: tony2001 Wed, 02 Nov 2011 21:05:36 + Revision: http://svn.php.net/viewvc?view=revisionrevision=318705 Log: initialize variable and fix segfaulting tests Thanks for catching this one and the one in svnrev 318723. Do you have test cases which trigger these bugs by any chance? Thanks Stefan -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods05.phpt branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt branches/PHP_5_4/Zend/zend_compile.c trunk/
gron Tue, 01 Nov 2011 13:42:53 + Revision: http://svn.php.net/viewvc?view=revisionrevision=318646 Log: Added missing consistency check for abstract methods required by one trait and implemented by another. Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods05.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods05.phpt A php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods06.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods05.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods05.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods05.phpt 2011-11-01 13:42:53 UTC (rev 318646) @@ -0,0 +1,25 @@ +--TEST-- +The compatibility with the signature of abstract methods should be checked. +--FILE-- +?php +error_reporting(E_ALL); + +trait THelloB { + public function hello() { + echo 'Hello'; + } +} + +trait THelloA { + public abstract function hello($a); +} + +class TraitsTest1 { + use THelloB; + use THelloA; +} + + +? +--EXPECTF-- +Fatal error: Declaration of THelloB::hello() must be compatible with THelloA::hello($a) in %s on line %d \ No newline at end of file Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt 2011-11-01 13:42:53 UTC (rev 318646) @@ -0,0 +1,26 @@ +--TEST-- +The compatibility with the signature of abstract methods should be checked. (also checking the second possible implementation branch) +--FILE-- +?php +error_reporting(E_ALL); + +trait THelloB { + public function hello() { +echo 'Hello'; + } +} + +trait THelloA { + public abstract function hello($a); +} + +class TraitsTest1 { + use THelloA; + use THelloB; +} + + + +? +--EXPECTF-- +Fatal error: Declaration of THelloB::hello() must be compatible with THelloA::hello($a) in %s on line %d \ No newline at end of file Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-11-01 13:31:27 UTC (rev 318645) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-11-01 13:42:53 UTC (rev 318646) @@ -3616,6 +3616,9 @@ if (zend_hash_quick_find(function_tables[i], hash_key-arKey, hash_key-nKeyLength, hash_key-h, (void **)other_trait_fn) == SUCCESS) { /* if it is an abstract method, there is no collision */ if (other_trait_fn-common.fn_flags ZEND_ACC_ABSTRACT) { + /* Make sure they are compatible */ + do_inheritance_check_on_method(fn, other_trait_fn TSRMLS_CC); + /* we can savely free and remove it from other table */ zend_function_dtor(other_trait_fn); zend_hash_quick_del(function_tables[i], hash_key-arKey, hash_key-nKeyLength, hash_key-h); @@ -3623,6 +3626,9 @@ /* if it is not an abstract method, there is still no collision */ /* if fn is an abstract method */ if (fn-common.fn_flags ZEND_ACC_ABSTRACT) { + /* Make sure they are compatible */ + do_inheritance_check_on_method(other_trait_fn, fn TSRMLS_CC); + /* just mark as solved, will be added if its own trait is processed */ abstract_solved = 1; } else { Added: php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods05.phpt === --- php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods05.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods05.phpt 2011-11-01 13:42:53 UTC (rev 318646) @@ -0,0 +1,25 @@ +--TEST-- +The compatibility with the signature of abstract methods should be checked. +--FILE-- +?php +error_reporting(E_ALL); + +trait THelloB { + public function hello() { + echo 'Hello'; + } +} + +trait THelloA { + public abstract function hello($a); +} + +class TraitsTest1 { + use THelloB; + use THelloA; +} + + +?
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bug60153.phpt branches/PHP_5_4/Zend/tests/traits/inheritance003.phpt branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/tests/traits/bug601
gron Tue, 01 Nov 2011 15:25:24 + Revision: http://svn.php.net/viewvc?view=revisionrevision=318650 Log: Fixed Bug #60153 (Interface method prototypes not enforced when implementd via traits.) # Moved the freeing of overriden functions to a point after the check. # The new check comes after the normal inheritance check to give the first check # the opportunity to abort with a more detailed error. # Also fixed a small type in an unrelated test. Bug: https://bugs.php.net/60153 (Open) Interface method prototypes not enforced when implementd via traits. Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60153.phpt U php/php-src/branches/PHP_5_4/Zend/tests/traits/inheritance003.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bug60153.phpt U php/php-src/trunk/Zend/tests/traits/inheritance003.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60153.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60153.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60153.phpt 2011-11-01 15:25:24 UTC (rev 318650) @@ -0,0 +1,19 @@ +--TEST-- +Bug #60153 (Interface method prototypes not enforced when implementd via traits.) +--FILE-- +?php + +interface IFoo { +public function oneArgument($a); +} + +trait TFoo { + public function oneArgument() {} +} + +class C implements IFoo { + use TFoo; +} + +--EXPECTF-- +Fatal error: Declaration of C::oneArgument() must be compatible with IFoo::oneArgument($a) in %s on line %d Modified: php/php-src/branches/PHP_5_4/Zend/tests/traits/inheritance003.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/inheritance003.phpt 2011-11-01 15:15:51 UTC (rev 318649) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/inheritance003.phpt 2011-11-01 15:25:24 UTC (rev 318650) @@ -1,5 +1,5 @@ --TEST-- -Trait method overriddes base class method and satisfies prototype +Trait method overrides base class method and satisfies prototype --FILE-- ?php error_reporting(E_ALL); Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-11-01 15:15:51 UTC (rev 318649) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-11-01 15:25:24 UTC (rev 318650) @@ -3831,14 +3831,6 @@ add = 1; /* not found */ } else if (existing_fn-common.scope != ce) { add = 1; /* or inherited from other class or interface */ - /* it is just a reference which was added to the subclass while doing the inheritance */ - /* so we can deleted now, and will add the overriding method afterwards */ - - /* except, if we try to add an abstract function, then we should not delete the inherited one */ - /* delete inherited fn if the function to be added is not abstract */ - if ((fn-common.fn_flags ZEND_ACC_ABSTRACT) == 0) { - zend_hash_quick_del(ce-function_table, hash_key-arKey, hash_key-nKeyLength, hash_key-h); - } } if (add) { @@ -3871,7 +3863,24 @@ if (prototype) { do_inheritance_check_on_method(fn, prototype TSRMLS_CC); } + /* one more thing: make sure we properly implement an abstract method */ + if (existing_fn existing_fn-common.fn_flags ZEND_ACC_ABSTRACT) { + do_inheritance_check_on_method(fn, existing_fn TSRMLS_CC); + } + /* delete inherited fn if the function to be added is not abstract */ + if (existing_fn +existing_fn-common.scope != ce +(fn-common.fn_flags ZEND_ACC_ABSTRACT) == 0) { + /* it is just a reference which was added to the subclass while doing + the inheritance, so we can deleted now, and will add the overriding + method afterwards. + Except, if we try to add an abstract function, then we should not + delete the inherited one */ + zend_hash_quick_del(ce-function_table, hash_key-arKey, hash_key-nKeyLength, hash_key-h); + } + + if (fn-common.fn_flags ZEND_ACC_ABSTRACT) { ce-ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS; } Added: php/php-src/trunk/Zend/tests/traits/bug60153.phpt === --- php/php-src/trunk/Zend/tests/traits/bug60153.phpt
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bug60173.phpt branches/PHP_5_4/Zend/zend_API.c trunk/Zend/tests/traits/bug60173.phpt trunk/Zend/zend_API.c
gron Mon, 31 Oct 2011 22:59:00 + Revision: http://svn.php.net/viewvc?view=revisionrevision=318621 Log: Fixed Bug #60173 (Wrong error message on reflective trait instantiation) Bug: https://bugs.php.net/60173 (Assigned) Wrong message on trait instantiation Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60173.phpt U php/php-src/branches/PHP_5_4/Zend/zend_API.c A php/php-src/trunk/Zend/tests/traits/bug60173.phpt U php/php-src/trunk/Zend/zend_API.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60173.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60173.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60173.phpt 2011-10-31 22:59:00 UTC (rev 318621) @@ -0,0 +1,12 @@ +--TEST-- +Bug #60173 (Wrong error message on reflective trait instantiation) +--FILE-- +?php + +trait foo { } + +$rc = new ReflectionClass('foo'); +$rc-newInstance(); + +--EXPECTF-- +Fatal error: Cannot instantiate trait foo in %s on line %d Modified: php/php-src/branches/PHP_5_4/Zend/zend_API.c === --- php/php-src/branches/PHP_5_4/Zend/zend_API.c2011-10-31 21:49:35 UTC (rev 318620) +++ php/php-src/branches/PHP_5_4/Zend/zend_API.c2011-10-31 22:59:00 UTC (rev 318621) @@ -1107,7 +1107,9 @@ zend_object *object; if (class_type-ce_flags (ZEND_ACC_INTERFACE|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) { - char *what = class_type-ce_flags ZEND_ACC_INTERFACE ? interface : abstract class; + char *what = (class_type-ce_flags ZEND_ACC_INTERFACE) ? interface +:((class_type-ce_flags ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) ? trait +: abstract class; zend_error(E_ERROR, Cannot instantiate %s %s, what, class_type-name); } Added: php/php-src/trunk/Zend/tests/traits/bug60173.phpt === --- php/php-src/trunk/Zend/tests/traits/bug60173.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bug60173.phpt 2011-10-31 22:59:00 UTC (rev 318621) @@ -0,0 +1,12 @@ +--TEST-- +Bug #60173 (Wrong error message on reflective trait instantiation) +--FILE-- +?php + +trait foo { } + +$rc = new ReflectionClass('foo'); +$rc-newInstance(); + +--EXPECTF-- +Fatal error: Cannot instantiate trait foo in %s on line %d Modified: php/php-src/trunk/Zend/zend_API.c === --- php/php-src/trunk/Zend/zend_API.c 2011-10-31 21:49:35 UTC (rev 318620) +++ php/php-src/trunk/Zend/zend_API.c 2011-10-31 22:59:00 UTC (rev 318621) @@ -1107,7 +1107,9 @@ zend_object *object; if (class_type-ce_flags (ZEND_ACC_INTERFACE|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) { - char *what = class_type-ce_flags ZEND_ACC_INTERFACE ? interface : abstract class; + char *what = (class_type-ce_flags ZEND_ACC_INTERFACE) ? interface +:((class_type-ce_flags ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) ? trait +: abstract class; zend_error(E_ERROR, Cannot instantiate %s %s, what, class_type-name); } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bug60145.phpt branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/tests/traits/bug60145.phpt trunk/Zend/zend_compile.c
gron Tue, 01 Nov 2011 00:39:10 + Revision: http://svn.php.net/viewvc?view=revisionrevision=318625 Log: Fixed Bug #60145 (Usage of trait's use statement inside interfaces not properly checked.) Bug: https://bugs.php.net/60145 (Assigned) interface + use trait yields error for the abstract class? Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60145.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bug60145.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60145.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60145.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug60145.phpt 2011-11-01 00:39:10 UTC (rev 318625) @@ -0,0 +1,17 @@ +--TEST-- +Bug #60145 (Usage of trait's use statement inside interfaces not properly checked.) +--FILE-- +?php + +trait foo { + +} + +interface MyInterface { + use foo; + + public function b(); + +} +--EXPECTF-- +Fatal error: Cannot use traits inside of interfaces. foo is used in MyInterface in %s on line %d Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-11-01 00:08:34 UTC (rev 318624) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-11-01 00:39:10 UTC (rev 318625) @@ -5023,7 +5023,13 @@ void zend_do_implements_trait(znode *trait_name TSRMLS_DC) /* {{{ */ { zend_op *opline; + if ((CG(active_class_entry)-ce_flags ZEND_ACC_INTERFACE)) { +zend_error(E_COMPILE_ERROR, + Cannot use traits inside of interfaces. %s is used in %s, + Z_STRVAL(trait_name-u.constant), CG(active_class_entry)-name); + } + switch (zend_get_class_fetch_type(Z_STRVAL(trait_name-u.constant), Z_STRLEN(trait_name-u.constant))) { case ZEND_FETCH_CLASS_SELF: case ZEND_FETCH_CLASS_PARENT: Added: php/php-src/trunk/Zend/tests/traits/bug60145.phpt === --- php/php-src/trunk/Zend/tests/traits/bug60145.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bug60145.phpt 2011-11-01 00:39:10 UTC (rev 318625) @@ -0,0 +1,17 @@ +--TEST-- +Bug #60145 (Usage of trait's use statement inside interfaces not properly checked.) +--FILE-- +?php + +trait foo { + +} + +interface MyInterface { + use foo; + + public function b(); + +} +--EXPECTF-- +Fatal error: Cannot use traits inside of interfaces. foo is used in MyInterface in %s on line %d Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2011-11-01 00:08:34 UTC (rev 318624) +++ php/php-src/trunk/Zend/zend_compile.c 2011-11-01 00:39:10 UTC (rev 318625) @@ -5023,7 +5023,13 @@ void zend_do_implements_trait(znode *trait_name TSRMLS_DC) /* {{{ */ { zend_op *opline; + if ((CG(active_class_entry)-ce_flags ZEND_ACC_INTERFACE)) { +zend_error(E_COMPILE_ERROR, + Cannot use traits inside of interfaces. %s is used in %s, + Z_STRVAL(trait_name-u.constant), CG(active_class_entry)-name); + } + switch (zend_get_class_fetch_type(Z_STRVAL(trait_name-u.constant), Z_STRLEN(trait_name-u.constant))) { case ZEND_FETCH_CLASS_SELF: case ZEND_FETCH_CLASS_PARENT: -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bug55554a.phpt branches/PHP_5_4/Zend/tests/traits/bug55554b.phpt branches/PHP_5_4/Zend/tests/traits/bug55554c.phpt branches/PHP_5_4/Zend
gron Sun, 09 Oct 2011 11:13:27 + Revision: http://svn.php.net/viewvc?view=revisionrevision=317935 Log: Fixed Bug #4 (Legacy constructors not handled properly) [TRAITS] [DOC] # The handling of legacy constructors defined by traits was corrected. # They are now properly registered and used on instantiation. # The situation for conflicting legacy and __construct constructors is # mostly identical. If they are defined in the class, they override conflicts # and do not collide. However, in case different styles are mixed, between # class and trait definition, we assume a programmer's mistake and report # a collision. # # BTW: +1 for all the fixed tests! `make test` is fun again. Bug: https://bugs.php.net/4 (Assigned) Trait methods overriding legacy constructors Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4a.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4b.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4c.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4d.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4e.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4f.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4g.phpt U php/php-src/branches/PHP_5_4/Zend/tests/traits/language009.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bug4a.phpt A php/php-src/trunk/Zend/tests/traits/bug4b.phpt A php/php-src/trunk/Zend/tests/traits/bug4c.phpt A php/php-src/trunk/Zend/tests/traits/bug4d.phpt A php/php-src/trunk/Zend/tests/traits/bug4e.phpt A php/php-src/trunk/Zend/tests/traits/bug4f.phpt A php/php-src/trunk/Zend/tests/traits/bug4g.phpt U php/php-src/trunk/Zend/tests/traits/language009.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4a.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4a.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4a.phpt 2011-10-09 11:13:27 UTC (rev 317935) @@ -0,0 +1,34 @@ +--TEST-- +Bug #55137 (Legacy constructor not registered for class) +--FILE-- +?php + +// All constructors should be registered as such + +trait TConstructor { +public function constructor() { +echo ctor executed\n; +} +} + +class NewConstructor { + use TConstructor { + constructor as __construct; + } +} + +class LegacyConstructor { +use TConstructor { +constructor as LegacyConstructor; +} +} + +echo New constructor: ; +$o = new NewConstructor; + +echo Legacy constructor: ; +$o = new LegacyConstructor; + +--EXPECT-- +New constructor: ctor executed +Legacy constructor: ctor executed Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4b.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4b.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4b.phpt 2011-10-09 11:13:27 UTC (rev 317935) @@ -0,0 +1,56 @@ +--TEST-- +Bug #55137 (Legacy constructor not registered for class) +--FILE-- +?php + +trait TConstructor { +public function foo() { +echo foo executed\n; +} +public function bar() { +echo bar executed\n; +} +} + +class OverridingIsSilent1 { +use TConstructor { + foo as __construct; + } + + public function __construct() { + echo OverridingIsSilent1 __construct\n; + } +} + +$o = new OverridingIsSilent1; + +class OverridingIsSilent2 { +use TConstructor { + foo as OverridingIsSilent2; + } + + public function OverridingIsSilent2() { + echo OverridingIsSilent2 OverridingIsSilent2\n; + } +} + +$o = new OverridingIsSilent2; + +class ReportCollision { + use TConstructor { + bar as ReportCollision; + foo as __construct; + } +} + + +echo ReportCollision: ; +$o = new ReportCollision; + + +--EXPECTF-- +OverridingIsSilent1 __construct +OverridingIsSilent2 OverridingIsSilent2 + +Fatal error: ReportCollision has colliding constructor definitions coming from traits in %s on line %d + Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4c.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4c.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug4c.phpt 2011-10-09 11:13:27 UTC (rev 317935) @@ -0,0 +1,46 @@ +--TEST-- +Bug #55137 (Legacy constructor not registered for class) +--FILE-- +?php + +// Test that the behavior is consistent with the existing handling of new +// and legacy constructors. +// Here, the traits conflicts are overridden by local definitions, +// and the two
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/zend_compile.c
gron Sat, 08 Oct 2011 23:47:16 + Revision: http://svn.php.net/viewvc?view=revisionrevision=317930 Log: Use ZEND_ constants instead of plain strings for names of magic methods. # No functional changes. Changed paths: U php/php-src/branches/PHP_5_4/Zend/zend_compile.c U php/php-src/trunk/Zend/zend_compile.c Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-10-08 23:42:36 UTC (rev 317929) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-10-08 23:47:16 UTC (rev 317930) @@ -3658,16 +3658,16 @@ strncmp(mname, str, mname_len) #define _ADD_MAGIC_METHOD(ce, mname, mname_len, fe) { \ - if (!IS_EQUAL(mname, mname_len, __clone)) { (ce)-clone = (fe); (fe)-common.fn_flags |= ZEND_ACC_CLONE; } \ - else if (!IS_EQUAL(mname, mname_len, __construct)) { (ce)-constructor = (fe); (fe)-common.fn_flags |= ZEND_ACC_CTOR; } \ - else if (!IS_EQUAL(mname, mname_len, __destruct)) { (ce)-destructor = (fe); (fe)-common.fn_flags |= ZEND_ACC_DTOR; } \ - else if (!IS_EQUAL(mname, mname_len, __get)) (ce)-__get = (fe); \ - else if (!IS_EQUAL(mname, mname_len, __set)) (ce)-__set = (fe); \ - else if (!IS_EQUAL(mname, mname_len, __call)) (ce)-__call = (fe); \ - else if (!IS_EQUAL(mname, mname_len, __unset)) (ce)-__unset = (fe); \ - else if (!IS_EQUAL(mname, mname_len, __isset)) (ce)-__isset = (fe); \ - else if (!IS_EQUAL(mname, mname_len, __callstatic))(ce)-__callstatic = (fe); \ - else if (!IS_EQUAL(mname, mname_len, __tostring)) (ce)-__tostring= (fe); \ + if ( !IS_EQUAL(mname, mname_len, ZEND_CLONE_FUNC_NAME)) { (ce)-clone = (fe); (fe)-common.fn_flags |= ZEND_ACC_CLONE; } \ + else if (!IS_EQUAL(mname, mname_len, ZEND_CONSTRUCTOR_FUNC_NAME)) { (ce)-constructor = (fe); (fe)-common.fn_flags |= ZEND_ACC_CTOR; } \ + else if (!IS_EQUAL(mname, mname_len, ZEND_DESTRUCTOR_FUNC_NAME)) { (ce)-destructor = (fe); (fe)-common.fn_flags |= ZEND_ACC_DTOR; } \ + else if (!IS_EQUAL(mname, mname_len, ZEND_GET_FUNC_NAME)) (ce)-__get = (fe); \ + else if (!IS_EQUAL(mname, mname_len, ZEND_SET_FUNC_NAME)) (ce)-__set = (fe); \ + else if (!IS_EQUAL(mname, mname_len, ZEND_CALL_FUNC_NAME)) (ce)-__call = (fe); \ + else if (!IS_EQUAL(mname, mname_len, ZEND_UNSET_FUNC_NAME)) (ce)-__unset= (fe); \ + else if (!IS_EQUAL(mname, mname_len, ZEND_ISSET_FUNC_NAME)) (ce)-__isset= (fe); \ + else if (!IS_EQUAL(mname, mname_len, ZEND_CALLSTATIC_FUNC_NAME)) (ce)-__callstatic = (fe); \ + else if (!IS_EQUAL(mname, mname_len, ZEND_TOSTRING_FUNC_NAME)) (ce)-__tostring = (fe); \ } /* {{{ Originates from php_runkit_function_copy_ctor Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2011-10-08 23:42:36 UTC (rev 317929) +++ php/php-src/trunk/Zend/zend_compile.c 2011-10-08 23:47:16 UTC (rev 317930) @@ -3658,16 +3658,16 @@ strncmp(mname, str, mname_len) #define _ADD_MAGIC_METHOD(ce, mname, mname_len, fe) { \ - if (!IS_EQUAL(mname, mname_len, __clone)) { (ce)-clone = (fe); (fe)-common.fn_flags |= ZEND_ACC_CLONE; } \ - else if (!IS_EQUAL(mname, mname_len, __construct)) { (ce)-constructor = (fe); (fe)-common.fn_flags |= ZEND_ACC_CTOR; } \ - else if (!IS_EQUAL(mname, mname_len, __destruct)) { (ce)-destructor = (fe); (fe)-common.fn_flags |= ZEND_ACC_DTOR; } \ - else if (!IS_EQUAL(mname, mname_len, __get)) (ce)-__get = (fe); \ - else if (!IS_EQUAL(mname, mname_len, __set)) (ce)-__set = (fe); \ - else if (!IS_EQUAL(mname, mname_len, __call)) (ce)-__call = (fe); \ - else if (!IS_EQUAL(mname, mname_len, __unset)) (ce)-__unset = (fe); \ - else if (!IS_EQUAL(mname, mname_len, __isset)) (ce)-__isset = (fe); \ - else if (!IS_EQUAL(mname, mname_len, __callstatic))(ce)-__callstatic = (fe); \ - else if (!IS_EQUAL(mname, mname_len, __tostring)) (ce)-__tostring= (fe); \ + if ( !IS_EQUAL(mname, mname_len, ZEND_CLONE_FUNC_NAME)) { (ce)-clone = (fe); (fe)-common.fn_flags |= ZEND_ACC_CLONE; } \ + else if (!IS_EQUAL(mname, mname_len, ZEND_CONSTRUCTOR_FUNC_NAME)) { (ce)-constructor = (fe); (fe)-common.fn_flags |= ZEND_ACC_CTOR; } \ + else if (!IS_EQUAL(mname,
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bug55524.phpt branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/tests/traits/bug55524.phpt trunk/Zend/zend_compile.c
gron Mon, 29 Aug 2011 15:53:46 + Revision: http://svn.php.net/viewvc?view=revisionrevision=315712 Log: Fixed bug #55524 Traits should not be able to extend a class # also used the Z_STRVAL where it seemed appropriate Bug: https://bugs.php.net/55524 (Assigned) Traits should not be able to extend a class Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55524.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bug55524.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55524.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55524.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55524.phpt 2011-08-29 15:53:46 UTC (rev 315712) @@ -0,0 +1,15 @@ +--TEST-- +Bug #55524 Traits should not be able to extend a class +--FILE-- +?php + +class Base {} + +trait Foo extends Base { +function bar() {} +} + +echo 'DONE'; +? +--EXPECTF-- +Fatal error: A trait (Foo) cannot extend a class in %s on line %d Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-08-29 15:44:23 UTC (rev 315711) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-08-29 15:53:46 UTC (rev 315712) @@ -4640,7 +4640,7 @@ if (!(strcmp(lcname, self) strcmp(lcname, parent))) { efree(lcname); - zend_error(E_COMPILE_ERROR, Cannot use '%s' as class name as it is reserved, class_name-u.constant.value.str.val); + zend_error(E_COMPILE_ERROR, Cannot use '%s' as class name as it is reserved, Z_STRVAL(class_name-u.constant)); } /* Class name must not conflict with import names */ @@ -4707,6 +4707,11 @@ opline-op2_type = IS_CONST; if (doing_inheritance) { + /* Make sure a trait does not try to extend a class */ + if ((new_class_entry-ce_flags ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) { + zend_error(E_COMPILE_ERROR, A trait (%s) cannot extend a class, new_class_entry-name); + } + opline-extended_value = parent_class_name-u.op.var; opline-opcode = ZEND_DECLARE_INHERITED_CLASS; } else { Added: php/php-src/trunk/Zend/tests/traits/bug55524.phpt === --- php/php-src/trunk/Zend/tests/traits/bug55524.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bug55524.phpt 2011-08-29 15:53:46 UTC (rev 315712) @@ -0,0 +1,15 @@ +--TEST-- +Bug #55524 Traits should not be able to extend a class +--FILE-- +?php + +class Base {} + +trait Foo extends Base { +function bar() {} +} + +echo 'DONE'; +? +--EXPECTF-- +Fatal error: A trait (Foo) cannot extend a class in %s on line %d Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2011-08-29 15:44:23 UTC (rev 315711) +++ php/php-src/trunk/Zend/zend_compile.c 2011-08-29 15:53:46 UTC (rev 315712) @@ -4640,7 +4640,7 @@ if (!(strcmp(lcname, self) strcmp(lcname, parent))) { efree(lcname); - zend_error(E_COMPILE_ERROR, Cannot use '%s' as class name as it is reserved, class_name-u.constant.value.str.val); + zend_error(E_COMPILE_ERROR, Cannot use '%s' as class name as it is reserved, Z_STRVAL(class_name-u.constant)); } /* Class name must not conflict with import names */ @@ -4707,6 +4707,11 @@ opline-op2_type = IS_CONST; if (doing_inheritance) { + /* Make sure a trait does not try to extend a class */ + if ((new_class_entry-ce_flags ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) { + zend_error(E_COMPILE_ERROR, A trait (%s) cannot extend a class, new_class_entry-name); + } + opline-extended_value = parent_class_name-u.op.var; opline-opcode = ZEND_DECLARE_INHERITED_CLASS; } else { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/zend_compile.c
Hi Hannes: On 16 Aug 2011, at 12:46, Hannes Magnusson wrote: + if (!strcmp(Z_STRVAL_P(name), strict)) { + zend_error(E_COMPILE_ERROR, You seem to be trying to use a different language...); + } Could we change that error to be a bit more explicit about what is not expected? Best regards Stefan -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/zend_compile.c
On 16 Aug 2011, at 13:23, Hannes Magnusson wrote: On Tue, Aug 16, 2011 at 13:05, Stefan Marr p...@stefan-marr.de wrote: Hi Hannes: On 16 Aug 2011, at 12:46, Hannes Magnusson wrote: + if (!strcmp(Z_STRVAL_P(name), strict)) { + zend_error(E_COMPILE_ERROR, You seem to be trying to use a different language...); + } Could we change that error to be a bit more explicit about what is not expected? I'm unsure what you are asking... Sorry, I don't know anything about the context of that change, but I don't see how anyone but you knows what 'zend_error(E_COMPILE_ERROR, You seem to be trying to use a different language...);' means when it pops up in an error output. The goal of an error message should be to help to identify the cause for it, and even better to help to avoid it in the future, right? Best regards Stefan -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/zend_compile.c
gron Mon, 15 Aug 2011 08:29:48 + Revision: http://svn.php.net/viewvc?view=revisionrevision=314921 Log: Addendum for patch to bug #55214: Class name was freed before method literal referring to it. # Thanks to Felipe for catching this. # The fix duplicates the name into the literal to avoid the dependency Bug: https://bugs.php.net/55214 (To be documented) use of __CLASS__ within trait returns trait name not class name Changed paths: U php/php-src/branches/PHP_5_4/Zend/zend_compile.c U php/php-src/trunk/Zend/zend_compile.c Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-08-15 07:38:54 UTC (rev 314920) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-08-15 08:29:48 UTC (rev 314921) @@ -3544,7 +3544,7 @@ /* Only on merge into an actual class */ (ZEND_ACC_TRAIT != (target_ce-ce_flags ZEND_ACC_TRAIT))) { INIT_ZVAL(class_name_zv); - ZVAL_STRINGL(class_name_zv, target_ce-name, target_ce-name_length, 0); + ZVAL_STRINGL(class_name_zv, target_ce-name, target_ce-name_length, 1); class_name_literal = zend_add_literal(fe-op_array, class_name_zv TSRMLS_CC); opcode_copy[i].op1.zv = fe-op_array.literals[class_name_literal].constant; } @@ -3564,7 +3564,7 @@ /* Only on merge into an actual class */ (ZEND_ACC_TRAIT != (target_ce-ce_flags ZEND_ACC_TRAIT))) { INIT_ZVAL(class_name_zv); - ZVAL_STRINGL(class_name_zv, target_ce-name, target_ce-name_length, 0); + ZVAL_STRINGL(class_name_zv, target_ce-name, target_ce-name_length, 1); class_name_literal = zend_add_literal(fe-op_array, class_name_zv TSRMLS_CC); opcode_copy[i].op2.zv = fe-op_array.literals[class_name_literal].constant; } Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2011-08-15 07:38:54 UTC (rev 314920) +++ php/php-src/trunk/Zend/zend_compile.c 2011-08-15 08:29:48 UTC (rev 314921) @@ -3544,7 +3544,7 @@ /* Only on merge into an actual class */ (ZEND_ACC_TRAIT != (target_ce-ce_flags ZEND_ACC_TRAIT))) { INIT_ZVAL(class_name_zv); - ZVAL_STRINGL(class_name_zv, target_ce-name, target_ce-name_length, 0); + ZVAL_STRINGL(class_name_zv, target_ce-name, target_ce-name_length, 1); class_name_literal = zend_add_literal(fe-op_array, class_name_zv TSRMLS_CC); opcode_copy[i].op1.zv = fe-op_array.literals[class_name_literal].constant; } @@ -3564,7 +3564,7 @@ /* Only on merge into an actual class */ (ZEND_ACC_TRAIT != (target_ce-ce_flags ZEND_ACC_TRAIT))) { INIT_ZVAL(class_name_zv); - ZVAL_STRINGL(class_name_zv, target_ce-name, target_ce-name_length, 0); + ZVAL_STRINGL(class_name_zv, target_ce-name, target_ce-name_length, 1); class_name_literal = zend_add_literal(fe-op_array, class_name_zv TSRMLS_CC); opcode_copy[i].op2.zv = fe-op_array.literals[class_name_literal].constant; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bug55372.phpt branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/tests/traits/bug55372.phpt trunk/Zend/zend_compile.c
gron Mon, 15 Aug 2011 09:54:06 + Revision: http://svn.php.net/viewvc?view=revisionrevision=314933 Log: Fixed Bug #55372 Incorrect handling of literals led to memory corruption. # Dmitry you might want to review this patch, since I split up zend_add_literal # and added a version for post-pass_two() usage. Bug: https://bugs.php.net/55372 (Verified) Trait fails when method parameter has a default Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55372.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bug55372.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55372.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55372.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55372.phpt 2011-08-15 09:54:06 UTC (rev 314933) @@ -0,0 +1,28 @@ +--TEST-- +Bug #55372 (Literal handling in methods is inconsistent, causing memory corruption) +--FILE-- +?php + +trait testTrait { + public function testMethod() { + if (1) { + $letters1 = range('a', 'z', 1); + $letters2 = range('A', 'Z', 1); + $letters1 = 'foo'; + $letters2 = 'baarr'; + var_dump($letters1); + var_dump($letters2); + } + } +} + +class foo { + use testTrait; +} + +$x = new foo; +$x-testMethod(); +? +--EXPECT-- +string(3) foo +string(5) baarr Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2011-08-15 09:45:29 UTC (rev 314932) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2011-08-15 09:54:06 UTC (rev 314933) @@ -339,25 +339,47 @@ } /* }}} */ +/* Common part of zend_add_literal and zend_append_individual_literal */ +static inline void zend_insert_literal(zend_op_array *op_array, const zval *zv, int literal_position TSRMLS_DC) /* {{{ */ +{ + if (Z_TYPE_P(zv) == IS_STRING || Z_TYPE_P(zv) == IS_CONSTANT) { + zval *z = (zval*)zv; + Z_STRVAL_P(z) = zend_new_interned_string(Z_STRVAL_P(zv), Z_STRLEN_P(zv) + 1, 1 TSRMLS_CC); + } + CONSTANT_EX(op_array, literal_position) = *zv; + Z_SET_REFCOUNT(CONSTANT_EX(op_array, literal_position), 2); + Z_SET_ISREF(CONSTANT_EX(op_array, literal_position)); + op_array-literals[literal_position].hash_value = 0; + op_array-literals[literal_position].cache_slot = -1; +} +/* }}} */ + +/* Is used while compiling a function, using the context to keep track + of an approximate size to avoid to relocate to often. + Literals are truncated to actual size in the second compiler pass (pass_two()). */ int zend_add_literal(zend_op_array *op_array, const zval *zv TSRMLS_DC) /* {{{ */ { int i = op_array-last_literal; op_array-last_literal++; if (i = CG(context).literals_size) { - CG(context).literals_size += 16; /* FIXME */ + while (i = CG(context).literals_size) { + CG(context).literals_size += 16; /* FIXME */ + } op_array-literals = (zend_literal*)erealloc(op_array-literals, CG(context).literals_size * sizeof(zend_literal)); } - if (Z_TYPE_P(zv) == IS_STRING || Z_TYPE_P(zv) == IS_CONSTANT) { - zval *z = (zval*)zv; + zend_insert_literal(op_array, zv, i TSRMLS_CC); + return i; +} +/* }}} */ - Z_STRVAL_P(z) = - zend_new_interned_string(Z_STRVAL_P(zv), Z_STRLEN_P(zv) + 1, 1 TSRMLS_CC); - } - CONSTANT_EX(op_array, i) = *zv; - Z_SET_REFCOUNT(CONSTANT_EX(op_array, i), 2); - Z_SET_ISREF(CONSTANT_EX(op_array, i)); - op_array-literals[i].hash_value = 0; - op_array-literals[i].cache_slot = -1; +/* Is used after normal compilation to append an additional literal. + Allocation is done precisely here. */ +int zend_append_individual_literal(zend_op_array *op_array, const zval *zv TSRMLS_DC) /* {{{ */ +{ + int i = op_array-last_literal; + op_array-last_literal++; + op_array-literals = (zend_literal*)erealloc(op_array-literals, (i + 1) * sizeof(zend_literal)); + zend_insert_literal(op_array, zv, i TSRMLS_CC); return i; } /* }}} */ @@ -3488,6 +3510,7 @@ zval class_name_zv; int class_name_literal; int i; + int number_of_literals; if (fe-op_array.static_variables) { HashTable *tmpHash; @@ -3498,12 +3521,11 @@ fe-op_array.static_variables = tmpHash; } - - /* TODO: Verify that this size is a global thing, do not see why but is used - like this elsewhere */ - literals_copy = (zend_literal*)emalloc(CG(context).literals_size * sizeof(zend_literal)); - for (i = 0; i fe-op_array.last_literal; i++) { + number_of_literals = fe-op_array.last_literal; + literals_copy = (zend_literal*)emalloc(number_of_literals * sizeof(zend_literal)); + + for (i = 0; i number_of_literals; i++) { literals_copy[i] = fe-op_array.literals[i]; zval_copy_ctor(literals_copy[i].constant); } @@ -3538,14 +3560,15 @@ } else { /* if __CLASS__ i.e. T_CLASS_C was used, we need to
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bug55355.phpt branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/tests/traits/bug55355.phpt trunk/Zend/zend_compile.c
gron Mon, 15 Aug 2011 11:16:18 + Revision: http://svn.php.net/viewvc?view=revisionrevision=314943 Log: Fixed Bug #55355: Inheritance chain was not regarded when checking whether the abstract method of a trait is satisfied. Bug: https://bugs.php.net/55355 (Open) Unexpected fatal error when using abstract functions with traits Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55355.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bug55355.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55355.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55355.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55355.phpt 2011-08-15 11:16:18 UTC (rev 314943) @@ -0,0 +1,46 @@ +--TEST-- +Bug #55355 (Abstract functions required by a trait are not correctly found when implemented in an ancestor class) +--FILE-- +?php + +// A trait that has a abstract function +trait ATrait { + function bar() { + $this-foo(); + } + abstract function foo(); +} + +// A class on the second level in the +// inheritance chain +class Level2Impl { + function foo() {} +} + +class Level1Indirect extends Level2Impl {} + +// A class on the first level in the +// inheritance chain +class Level1Direct { +function foo() {} +} + +// Trait Uses + +class Direct { +use ATrait; +function foo() {} +} + +class BaseL2 extends Level1Indirect { +use ATrait; +} + +class BaseL1 extends Level1Direct { +use ATrait; +} + +echo 'DONE'; +? +--EXPECT-- +DONE Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-08-15 11:06:35 UTC (rev 314942) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-08-15 11:16:18 UTC (rev 314943) @@ -3645,6 +3645,14 @@ zend_function* parent_function; if (ce-parent zend_hash_quick_find(ce-parent-function_table, hash_key-arKey, hash_key-nKeyLength, hash_key-h, (void**) parent_function) != FAILURE) { prototype = parent_function; /* -common.fn_flags |= ZEND_ACC_ABSTRACT; */ + + /* we got that method in the parent class, and are going to override it, + except, if the trait is just asking to have an abstract method implemented. */ + if (fn-common.fn_flags ZEND_ACC_ABSTRACT) { + /* then we clean up an skip this method */ + zend_function_dtor(fn); + return ZEND_HASH_APPLY_REMOVE; + } } fn-common.scope = ce; Added: php/php-src/trunk/Zend/tests/traits/bug55355.phpt === --- php/php-src/trunk/Zend/tests/traits/bug55355.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bug55355.phpt 2011-08-15 11:16:18 UTC (rev 314943) @@ -0,0 +1,46 @@ +--TEST-- +Bug #55355 (Abstract functions required by a trait are not correctly found when implemented in an ancestor class) +--FILE-- +?php + +// A trait that has a abstract function +trait ATrait { + function bar() { + $this-foo(); + } + abstract function foo(); +} + +// A class on the second level in the +// inheritance chain +class Level2Impl { + function foo() {} +} + +class Level1Indirect extends Level2Impl {} + +// A class on the first level in the +// inheritance chain +class Level1Direct { +function foo() {} +} + +// Trait Uses + +class Direct { +use ATrait; +function foo() {} +} + +class BaseL2 extends Level1Indirect { +use ATrait; +} + +class BaseL1 extends Level1Direct { +use ATrait; +} + +echo 'DONE'; +? +--EXPECT-- +DONE Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2011-08-15 11:06:35 UTC (rev 314942) +++ php/php-src/trunk/Zend/zend_compile.c 2011-08-15 11:16:18 UTC (rev 314943) @@ -3645,6 +3645,14 @@ zend_function* parent_function; if (ce-parent zend_hash_quick_find(ce-parent-function_table, hash_key-arKey, hash_key-nKeyLength, hash_key-h, (void**) parent_function) != FAILURE) { prototype = parent_function; /* -common.fn_flags |= ZEND_ACC_ABSTRACT; */ + + /* we got that method in the parent class, and are going to override it, + except, if the trait is just asking to have an abstract method implemented. */ + if
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bug55424.phpt branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/tests/traits/bug55424.phpt trunk/Zend/zend_compile.c
gron Mon, 15 Aug 2011 22:16:58 + Revision: http://svn.php.net/viewvc?view=revisionrevision=314981 Log: Bug #55424 Fatal error when calling a method from a trait that is defined in parent class and required by using an abstract method in the trait. # The method got unconditionally deleted from the class, since it was assumed that we override it, but we did not in case of abstract methods coming from a trait. Thus, dont delete when we try to merge in an abstract method. Bug: https://bugs.php.net/55424 (Open) Fatal error when calling a method from a trait that is defined in parent class Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55424.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bug55424.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55424.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55424.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55424.phpt 2011-08-15 22:16:58 UTC (rev 314981) @@ -0,0 +1,35 @@ +--TEST-- +Bug #55424 (Method got missing from class when a trait defined an abstract method to express a requirement) +--FILE-- +?php + + trait ATrait + { + function setRequired() + { + $this-setAttribute(); + } + + abstract function setAttribute(); + } + + class Base + { + function setAttribute() { } + } + + class MyClass extends Base + { + use ATrait; + } + + $i = new Base(); + $i-setAttribute(); + + $t = new MyClass(); + /* setAttribute used to disappear for no good reason. */ + $t-setRequired(); + echo 'DONE'; +? +--EXPECT-- +DONE Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-08-15 20:41:33 UTC (rev 314980) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-08-15 22:16:58 UTC (rev 314981) @@ -3635,10 +3635,13 @@ } else if (existing_fn-common.scope != ce) { add = 1; /* or inherited from other class or interface */ /* it is just a reference which was added to the subclass while doing the inheritance */ - /* prototype = existing_fn; */ - /* memory is scrambled anyway */ - /* function_add_ref(prototype); */ - zend_hash_quick_del(ce-function_table, hash_key-arKey, hash_key-nKeyLength, hash_key-h); + /* so we can deleted now, and will add the overriding method afterwards */ + + /* except, if we try to add an abstract function, then we should not delete the inherited one */ + /* delete inherited fn if the function to be added is not abstract */ + if ((fn-common.fn_flags ZEND_ACC_ABSTRACT) == 0) { + zend_hash_quick_del(ce-function_table, hash_key-arKey, hash_key-nKeyLength, hash_key-h); + } } if (add) { Added: php/php-src/trunk/Zend/tests/traits/bug55424.phpt === --- php/php-src/trunk/Zend/tests/traits/bug55424.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bug55424.phpt 2011-08-15 22:16:58 UTC (rev 314981) @@ -0,0 +1,35 @@ +--TEST-- +Bug #55424 (Method got missing from class when a trait defined an abstract method to express a requirement) +--FILE-- +?php + + trait ATrait + { + function setRequired() + { + $this-setAttribute(); + } + + abstract function setAttribute(); + } + + class Base + { + function setAttribute() { } + } + + class MyClass extends Base + { + use ATrait; + } + + $i = new Base(); + $i-setAttribute(); + + $t = new MyClass(); + /* setAttribute used to disappear for no good reason. */ + $t-setRequired(); + echo 'DONE'; +? +--EXPECT-- +DONE Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2011-08-15 20:41:33 UTC (rev 314980) +++ php/php-src/trunk/Zend/zend_compile.c 2011-08-15 22:16:58 UTC (rev 314981) @@ -3635,10 +3635,13 @@ } else if (existing_fn-common.scope != ce) { add = 1; /* or inherited from other class or interface */ /* it is just a reference which was added to the subclass while doing the inheritance */ - /* prototype
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/property001.phpt trunk/Zend/tests/traits/property001.phpt
gron Sun, 31 Jul 2011 16:15:40 + Revision: http://svn.php.net/viewvc?view=revisionrevision=313992 Log: Fixed test which was assuming that E_STRICT is not on by default. Changed paths: U php/php-src/branches/PHP_5_4/Zend/tests/traits/property001.phpt U php/php-src/trunk/Zend/tests/traits/property001.phpt Modified: php/php-src/branches/PHP_5_4/Zend/tests/traits/property001.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/property001.phpt 2011-07-31 12:27:47 UTC (rev 313991) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/property001.phpt 2011-07-31 16:15:40 UTC (rev 313992) @@ -13,6 +13,7 @@ } echo PRE-CLASS-GUARD-TraitsTest\n; +error_reporting(E_ALL ~E_STRICT); // ensuring that it is only for E_STRICT class TraitsTest { use THello1; Modified: php/php-src/trunk/Zend/tests/traits/property001.phpt === --- php/php-src/trunk/Zend/tests/traits/property001.phpt2011-07-31 12:27:47 UTC (rev 313991) +++ php/php-src/trunk/Zend/tests/traits/property001.phpt2011-07-31 16:15:40 UTC (rev 313992) @@ -13,6 +13,7 @@ } echo PRE-CLASS-GUARD-TraitsTest\n; +error_reporting(E_ALL ~E_STRICT); // ensuring that it is only for E_STRICT class TraitsTest { use THello1; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/ext/tokenizer/tests/token_get_all_basic.phpt branches/PHP_5_4/ext/tokenizer/tests/token_get_all_error.phpt branches/PHP_5_4/ext/tokenizer/tests/token_get_
gron Sun, 31 Jul 2011 16:35:09 + Revision: http://svn.php.net/viewvc?view=revisionrevision=313993 Log: Added: SKIP when tokenizer extension is not available Changed paths: U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_basic.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_error.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation1.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation10.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation11.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation12.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation13.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation14.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation15.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation16.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation17.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation18.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation19.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation2.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation3.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation4.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation5.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation6.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation7.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation8.phpt U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation9.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_basic.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_error.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation1.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation10.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation11.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation12.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation13.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation14.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation15.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation16.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation17.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation18.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation19.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation2.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation3.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation4.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation5.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation6.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation7.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation8.phpt U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation9.phpt Modified: php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_basic.phpt === --- php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_basic.phpt 2011-07-31 16:15:40 UTC (rev 313992) +++ php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_basic.phpt 2011-07-31 16:35:09 UTC (rev 313993) @@ -1,5 +1,7 @@ --TEST-- Test token_get_all() function : basic functionality +--SKIPIF-- +?php if (!extension_loaded(tokenizer)) print skip; ? --FILE-- ?php /* Prototype : array token_get_all(string $source) Modified: php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_error.phpt === --- php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_error.phpt 2011-07-31 16:15:40 UTC (rev 313992) +++ php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_error.phpt 2011-07-31 16:35:09 UTC (rev 313993) @@ -1,5 +1,7 @@ --TEST-- Test token_get_all() function : error conditions +--SKIPIF-- +?php if (!extension_loaded(tokenizer)) print skip; ? --FILE-- ?php /* Prototype : array token_get_all(string $source) Modified: php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation1.phpt
Re: [PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/NEWS branches/PHP_5_4/Zend/zend_builtin_functions.c branches/PHP_5_4/Zend/zend_errors.h branches/PHP_5_4/php.ini-development branches/PHP_5_4/php.ini-
Hi: On Sun, Jul 24, 2011 at 12:07 AM, Stanislav Malyshev s...@php.net wrote: stas                   Sat, 23 Jul 2011 22:07:22 + Revision: http://svn.php.net/viewvc?view=revisionrevision=313645 Log: Change E_ALL to include E_STRICT Could please someone take the time to fix the tests which are related to that. I won't get to it today, sorry, but for instance Zend/tests/error_reporting* look like they need some adaptation. Thanks Stefan -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/trait_constant_001.phpt branches/PHP_5_4/Zend/tests/traits/trait_constant_002.phpt branches/PHP_5_4/Zend/zend_language_parser.y branches
gron Sun, 31 Jul 2011 17:39:30 + Revision: http://svn.php.net/viewvc?view=revisionrevision=313994 Log: Added __TRAIT__ magic constant [TRAITS] [DOC] # __TRAIT__ behaves like __CLASS__ more or less but is constraint to traits. # Since traits are not types, there are not many valid use cases, and trying # to use __TRAIT__ to make traits more like classes is discouraged. Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/trait_constant_001.phpt A php/php-src/branches/PHP_5_4/Zend/tests/traits/trait_constant_002.phpt U php/php-src/branches/PHP_5_4/Zend/zend_language_parser.y U php/php-src/branches/PHP_5_4/Zend/zend_language_scanner.c U php/php-src/branches/PHP_5_4/Zend/zend_language_scanner.l U php/php-src/branches/PHP_5_4/Zend/zend_language_scanner_defs.h U php/php-src/branches/PHP_5_4/ext/tokenizer/tests/token_get_all_variation12.phpt A php/php-src/trunk/Zend/tests/traits/trait_constant_001.phpt A php/php-src/trunk/Zend/tests/traits/trait_constant_002.phpt U php/php-src/trunk/Zend/zend_language_parser.y U php/php-src/trunk/Zend/zend_language_scanner.c U php/php-src/trunk/Zend/zend_language_scanner.l U php/php-src/trunk/Zend/zend_language_scanner_defs.h U php/php-src/trunk/ext/tokenizer/tests/token_get_all_variation12.phpt diffs exceeded maximum size -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/ext/spl/tests/class_uses_basic.phpt branches/PHP_5_4/ext/spl/tests/class_uses_basic2.phpt branches/PHP_5_4/ext/spl/tests/class_uses_variation.phpt branche
gron Sun, 24 Jul 2011 10:20:08 + Revision: http://svn.php.net/viewvc?view=revisionrevision=313649 Log: Added forgotten tests cases for class_uses() from commit rev. 313640 Changed paths: A php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_basic.phpt A php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_basic2.phpt A php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_variation.phpt A php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_variation1.phpt A php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_variation2.phpt A php/php-src/trunk/ext/spl/tests/class_uses_basic.phpt A php/php-src/trunk/ext/spl/tests/class_uses_basic2.phpt A php/php-src/trunk/ext/spl/tests/class_uses_variation.phpt A php/php-src/trunk/ext/spl/tests/class_uses_variation1.phpt A php/php-src/trunk/ext/spl/tests/class_uses_variation2.phpt Added: php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_basic.phpt === --- php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_basic.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_basic.phpt 2011-07-24 10:20:08 UTC (rev 313649) @@ -0,0 +1,33 @@ +--TEST-- +SPL: Test class_implements() function : basic +--FILE-- +?php +/* Prototype : array class_uses(mixed what [, bool autoload ]) + * Description: Return all traits used by a class + * Source code: ext/spl/php_spl.c + * Alias to functions: + */ + +echo *** Testing class_uses() : basic ***\n; + + +trait foo { } +class bar { use foo; } + +var_dump(class_uses(new bar)); +var_dump(class_uses('bar')); + + +? +===DONE=== +--EXPECT-- +*** Testing class_uses() : basic *** +array(1) { + [foo]= + string(3) foo +} +array(1) { + [foo]= + string(3) foo +} +===DONE=== Added: php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_basic2.phpt === --- php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_basic2.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_basic2.phpt 2011-07-24 10:20:08 UTC (rev 313649) @@ -0,0 +1,69 @@ +--TEST-- +SPL: Test class_uses() function : basic +--FILE-- +?php +/* Prototype : array class_uses(mixed what [, bool autoload ]) + * Description: Return all traits used by a class + * Source code: ext/spl/php_spl.c + * Alias to functions: + */ + +echo *** Testing class_uses() : basic ***\n; + + +trait foo { } +class fooUser { use foo; } + +trait bar { } +class barUser { use bar; } + +class foobarUser { use foo, bar; } + +/** There is no semantics for traits in the inheritance chain. +Traits are flattend into a class, and that semantics is nothing +like a type, or interface, and thus, not propergated. */ +class fooViaBarUser extends barUser { use foo; } + +class fooExtended extends fooUser {} + +s_var_dump(class_uses(new foobarUser)); +s_var_dump(class_uses('foobarUser')); +s_var_dump(class_uses(new fooViaBarUser)); +s_var_dump(class_uses('fooViaBarUser')); +s_var_dump(class_uses(new fooExtended)); +s_var_dump(class_uses('fooExtended')); + + +function s_var_dump($arr) { + krsort($arr); + var_dump($arr); +} +? +===DONE=== +--EXPECT-- +*** Testing class_uses() : basic *** +array(2) { + [foo]= + string(3) foo + [bar]= + string(3) bar +} +array(2) { + [foo]= + string(3) foo + [bar]= + string(3) bar +} +array(1) { + [foo]= + string(3) foo +} +array(1) { + [foo]= + string(3) foo +} +array(0) { +} +array(0) { +} +===DONE=== Added: php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_variation.phpt === --- php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_variation.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/ext/spl/tests/class_uses_variation.phpt 2011-07-24 10:20:08 UTC (rev 313649) @@ -0,0 +1,45 @@ +--TEST-- +SPL: Test class_uses() function : variation - no interfaces and autoload +--FILE-- +?php +/* Prototype : array class_uses(mixed what [, bool autoload ]) + * Description: Return all traits used by a class + * Source code: ext/spl/php_spl.c + * Alias to functions: + */ + +echo *** Testing class_uses() : variation ***\n; + +echo --- testing no traits ---\n; +class fs {} +var_dump(class_uses(new fs)); +var_dump(class_uses('fs')); + +echo \n--- testing autoload ---\n; +var_dump(class_uses('non-existent')); +var_dump(class_uses('non-existent2', false)); + + +function __autoload($classname) { + echo attempting to autoload $classname\n; +} + +? +===DONE=== +--EXPECTF-- +*** Testing class_uses() : variation *** +--- testing no traits --- +array(0) { +} +array(0) { +} + +--- testing autoload --- +attempting to autoload non-existent + +Warning: class_uses(): Class non-existent does not exist and could not be loaded in %s on line %d +bool(false) + +Warning: class_uses(): Class non-existent2 does
[PHP-CVS] svn: /php/php-src/branches/PHP_5_4/Zend/tests/traits/ bug55137.phpt
gron Sat, 23 Jul 2011 13:42:58 + Revision: http://svn.php.net/viewvc?view=revisionrevision=313630 Log: Added test case which was only added to trunk, bug seems to be fixed already. Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55137.phpt Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55137.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55137.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55137.phpt 2011-07-23 13:42:58 UTC (rev 313630) @@ -0,0 +1,26 @@ +--TEST-- +Bug #55137 (Changing trait static method visibility) +--FILE-- +?php + +trait A { + protected static function foo() { echo abc\n; } + private static function bar() { echo def\n; } +} + + +class B { + use A { + A::foo as public; + A::bar as public baz; + } +} + +B::foo(); +B::baz(); + + +? +--EXPECT-- +abc +def -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/tests/traits/bugs/overridding-con
gron Sat, 23 Jul 2011 13:48:07 + Revision: http://svn.php.net/viewvc?view=revisionrevision=313632 Log: Fixed bug in the handling of conflicting property initializers for traits. # Bug was uncovered by discussion in http://news.php.net/php.internals/54129 # Forgot to check the actual value of the initializer comparison, only checked # whether comparison was successful which is not enough. Changed paths: A php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt U php/php-src/branches/PHP_5_4/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt === --- php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt 2011-07-23 13:48:07 UTC (rev 313632) @@ -0,0 +1,23 @@ +--TEST-- +Properties are considered incompatible if they are different in any of their +defined characteristics. Thus, initialization values have to be equal, too. +--FILE-- +?php +error_reporting(E_ALL); + +trait foo +{ +public $zoo = 'foo::zoo'; +} + +class baz +{ +use foo; +public $zoo = 'baz::zoo'; +} + +$obj = new baz(); +echo $obj-zoo, \n; +? +--EXPECTF-- +Fatal error: baz and foo define the same property ($zoo) in the composition of baz. However, the definition differs and is considered incompatible. Class was composed in %s on line %d \ No newline at end of file Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-07-23 13:48:02 UTC (rev 313631) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-07-23 13:48:07 UTC (rev 313632) @@ -3919,13 +3919,15 @@ if ((coliding_prop-flags ZEND_ACC_PPP_MASK) == (property_info-flags ZEND_ACC_PPP_MASK)) { /* flags are identical, now the value needs to be checked */ if (property_info-flags ZEND_ACC_STATIC) { - not_compatible = compare_function(compare_result, - ce-default_static_members_table[coliding_prop-offset], - ce-traits[i]-default_static_members_table[property_info-offset] TSRMLS_CC) == FAILURE; +not_compatible = (FAILURE == compare_function(compare_result, + ce-default_static_members_table[coliding_prop-offset], + ce-traits[i]-default_static_members_table[property_info-offset] TSRMLS_CC)) + || (Z_LVAL(compare_result) != 0); } else { - not_compatible = compare_function(compare_result, - ce-default_properties_table[coliding_prop-offset], - ce-traits[i]-default_properties_table[property_info-offset] TSRMLS_CC) == FAILURE; + not_compatible = (FAILURE == compare_function(compare_result, + ce-default_properties_table[coliding_prop-offset], + ce-traits[i]-default_properties_table[property_info-offset] TSRMLS_CC)) + || (Z_LVAL(compare_result) != 0); } } else { /* the flags are not identical, thus, we assume properties are not compatible */ Added: php/php-src/trunk/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt === --- php/php-src/trunk/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bugs/overridding-conflicting-property-initializer.phpt 2011-07-23 13:48:07 UTC (rev 313632) @@ -0,0 +1,23 @@ +--TEST-- +Properties are considered incompatible if they are different in any of their +defined
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/zend_compile.c
gron Sat, 23 Jul 2011 18:12:31 + Revision: http://svn.php.net/viewvc?view=revisionrevision=313638 Log: Fixed incorrect initialization when copied op_array.vars was NULL (TRAITS) Changed paths: U php/php-src/branches/PHP_5_4/Zend/zend_compile.c U php/php-src/trunk/Zend/zend_compile.c Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c === --- php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-07-23 17:12:42 UTC (rev 313637) +++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c2011-07-23 18:12:31 UTC (rev 313638) @@ -3502,15 +3502,20 @@ fe-op_array.refcount = emalloc(sizeof(zend_uint)); *(fe-op_array.refcount) = 1; - i = fe-op_array.last_var; - dupvars = safe_emalloc(fe-op_array.last_var, sizeof(zend_compiled_variable), 0); - while (i 0) { - i--; - dupvars[i].name = estrndup(fe-op_array.vars[i].name, fe-op_array.vars[i].name_len); - dupvars[i].name_len = fe-op_array.vars[i].name_len; - dupvars[i].hash_value = fe-op_array.vars[i].hash_value; - } - fe-op_array.vars = dupvars; + if (fe-op_array.vars) { +i = fe-op_array.last_var; +dupvars = safe_emalloc(fe-op_array.last_var, sizeof(zend_compiled_variable), 0); +while (i 0) { + i--; + dupvars[i].name = estrndup(fe-op_array.vars[i].name, fe-op_array.vars[i].name_len); + dupvars[i].name_len = fe-op_array.vars[i].name_len; + dupvars[i].hash_value = fe-op_array.vars[i].hash_value; +} +fe-op_array.vars = dupvars; + } + else { +fe-op_array.vars = NULL; + } opcode_copy = safe_emalloc(sizeof(zend_op), fe-op_array.last, 0); for(i = 0; i fe-op_array.last; i++) { Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2011-07-23 17:12:42 UTC (rev 313637) +++ php/php-src/trunk/Zend/zend_compile.c 2011-07-23 18:12:31 UTC (rev 313638) @@ -3502,15 +3502,20 @@ fe-op_array.refcount = emalloc(sizeof(zend_uint)); *(fe-op_array.refcount) = 1; - i = fe-op_array.last_var; - dupvars = safe_emalloc(fe-op_array.last_var, sizeof(zend_compiled_variable), 0); - while (i 0) { - i--; - dupvars[i].name = estrndup(fe-op_array.vars[i].name, fe-op_array.vars[i].name_len); - dupvars[i].name_len = fe-op_array.vars[i].name_len; - dupvars[i].hash_value = fe-op_array.vars[i].hash_value; - } - fe-op_array.vars = dupvars; + if (fe-op_array.vars) { +i = fe-op_array.last_var; +dupvars = safe_emalloc(fe-op_array.last_var, sizeof(zend_compiled_variable), 0); +while (i 0) { + i--; + dupvars[i].name = estrndup(fe-op_array.vars[i].name, fe-op_array.vars[i].name_len); + dupvars[i].name_len = fe-op_array.vars[i].name_len; + dupvars[i].hash_value = fe-op_array.vars[i].hash_value; +} +fe-op_array.vars = dupvars; + } + else { +fe-op_array.vars = NULL; + } opcode_copy = safe_emalloc(sizeof(zend_op), fe-op_array.last, 0); for(i = 0; i fe-op_array.last; i++) { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/NEWS branches/PHP_5_4/ext/spl/php_spl.c branches/PHP_5_4/ext/spl/php_spl.h branches/PHP_5_4/ext/spl/spl_functions.c branches/PHP_5_4/ext/spl/spl_functions
gron Sat, 23 Jul 2011 19:08:43 + Revision: http://svn.php.net/viewvc?view=revisionrevision=313640 Log: Added missing class_uses(..) function to SPL to mirror class_implements(..). # Was pointed out as missing in bug #55266. Bug: https://bugs.php.net/55266 (Assigned) Traits vs Type hints Changed paths: U php/php-src/branches/PHP_5_4/NEWS U php/php-src/branches/PHP_5_4/ext/spl/php_spl.c U php/php-src/branches/PHP_5_4/ext/spl/php_spl.h U php/php-src/branches/PHP_5_4/ext/spl/spl_functions.c U php/php-src/branches/PHP_5_4/ext/spl/spl_functions.h U php/php-src/trunk/NEWS U php/php-src/trunk/ext/spl/php_spl.c U php/php-src/trunk/ext/spl/php_spl.h U php/php-src/trunk/ext/spl/spl_functions.c U php/php-src/trunk/ext/spl/spl_functions.h Modified: php/php-src/branches/PHP_5_4/NEWS === --- php/php-src/branches/PHP_5_4/NEWS 2011-07-23 18:19:12 UTC (rev 313639) +++ php/php-src/branches/PHP_5_4/NEWS 2011-07-23 19:08:43 UTC (rev 313640) @@ -12,6 +12,10 @@ . Dropped restriction of not setting the same value multiple times, the last one holds. (giovanni at giacobbi dot net, fat) +- SPL extension: + . Added missing class_uses(..) as pointed out by #55266 (Stefan) + + 14 Jul 2011, PHP 5.4.0 Alpha 2 - General improvements: . Zend Signal Handling. (Lucas Nealan,Arnaud Le Blanc,Brian Shire, Ilia) Modified: php/php-src/branches/PHP_5_4/ext/spl/php_spl.c === --- php/php-src/branches/PHP_5_4/ext/spl/php_spl.c 2011-07-23 18:19:12 UTC (rev 313639) +++ php/php-src/branches/PHP_5_4/ext/spl/php_spl.c 2011-07-23 19:08:43 UTC (rev 313640) @@ -166,6 +166,35 @@ } /* }}} */ +/* {{{ proto array class_uses(mixed what [, bool autoload ]) + Return all traits used by a class. */ +PHP_FUNCTION(class_uses) +{ + zval *obj; + zend_bool autoload = 1; + zend_class_entry *ce; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, z|b, obj, autoload) == FAILURE) { + RETURN_FALSE; + } + if (Z_TYPE_P(obj) != IS_OBJECT Z_TYPE_P(obj) != IS_STRING) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, object or string expected); + RETURN_FALSE; + } + + if (Z_TYPE_P(obj) == IS_STRING) { + if (NULL == (ce = spl_find_ce_by_name(Z_STRVAL_P(obj), Z_STRLEN_P(obj), autoload TSRMLS_CC))) { + RETURN_FALSE; + } + } else { + ce = Z_OBJCE_P(obj); + } + + array_init(return_value); + spl_add_traits(return_value, ce, 1, ZEND_ACC_TRAIT TSRMLS_CC); +} +/* }}} */ + #define SPL_ADD_CLASS(class_name, z_list, sub, allow, ce_flags) \ spl_add_classes(spl_ce_ ## class_name, z_list, sub, allow, ce_flags TSRMLS_CC) @@ -933,6 +962,12 @@ ZEND_ARG_INFO(0, autoload) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_uses, 0, 0, 1) + ZEND_ARG_INFO(0, what) + ZEND_ARG_INFO(0, autoload) +ZEND_END_ARG_INFO() + + ZEND_BEGIN_ARG_INFO(arginfo_spl_classes, 0) ZEND_END_ARG_INFO() @@ -977,6 +1012,7 @@ PHP_FE(spl_autoload_call, arginfo_spl_autoload_call) PHP_FE(class_parents, arginfo_class_parents) PHP_FE(class_implements,arginfo_class_implements) + PHP_FE(class_uses, arginfo_class_uses) PHP_FE(spl_object_hash, arginfo_spl_object_hash) #ifdef SPL_ITERATORS_H PHP_FE(iterator_to_array, arginfo_iterator_to_array) Modified: php/php-src/branches/PHP_5_4/ext/spl/php_spl.h === --- php/php-src/branches/PHP_5_4/ext/spl/php_spl.h 2011-07-23 18:19:12 UTC (rev 313639) +++ php/php-src/branches/PHP_5_4/ext/spl/php_spl.h 2011-07-23 19:08:43 UTC (rev 313640) @@ -85,6 +85,7 @@ PHP_FUNCTION(spl_classes); PHP_FUNCTION(class_parents); PHP_FUNCTION(class_implements); +PHP_FUNCTION(class_uses); PHPAPI void php_spl_object_hash(zval *obj, char* md5str TSRMLS_DC); Modified: php/php-src/branches/PHP_5_4/ext/spl/spl_functions.c === --- php/php-src/branches/PHP_5_4/ext/spl/spl_functions.c 2011-07-23 18:19:12 UTC (rev 313639) +++ php/php-src/branches/PHP_5_4/ext/spl/spl_functions.c 2011-07-23 19:08:43 UTC (rev 313640) @@ -103,6 +103,18 @@ } /* }}} */ +/* {{{ spl_add_traits */ +void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC) +{ + zend_uint num_traits; + + for (num_traits = 0; num_traits pce-num_traits; num_traits++) { + spl_add_class_name(list, pce-traits[num_traits], allow, ce_flags TSRMLS_CC); + } +} +/* }}} */ + + /* {{{ spl_add_classes */ int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC) { Modified: php/php-src/branches/PHP_5_4/ext/spl/spl_functions.h === --- php/php-src/branches/PHP_5_4/ext/spl/spl_functions.h 2011-07-23 18:19:12 UTC (rev 313639) +++
[PHP-CVS] svn: /php/php-src/trunk/Zend/ tests/traits/bugs/alias01.phpt tests/traits/language010.phpt zend_compile.c
gron Fri, 13 May 2011 20:28:34 + Revision: http://svn.php.net/viewvc?view=revisionrevision=310999 Log: Fixed a inconsitent condition for aliasing traits. - missed a failing Traits test, but is now fixed, and the bug covered by a dedicated test # Should always comment conditions that go over more than two lines :-/ Changed paths: A php/php-src/trunk/Zend/tests/traits/bugs/alias01.phpt U php/php-src/trunk/Zend/tests/traits/language010.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/trunk/Zend/tests/traits/bugs/alias01.phpt === --- php/php-src/trunk/Zend/tests/traits/bugs/alias01.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bugs/alias01.phpt 2011-05-13 20:28:34 UTC (rev 310999) @@ -0,0 +1,26 @@ +--TEST-- +Aliases are applied to the correct methods, and only to them. +--FILE-- +?php +trait T1 { + function m1() { echo T:m1\n; } + function m2() { echo T:m2\n; } +} + +class C1 { + use T1 { m1 as a1; } +} + +$o = new C1; +$o-m1(); +$o-a1(); +$o-m2(); +$o-a2(); + +? +--EXPECTF-- +T:m1 +T:m1 +T:m2 + +Fatal error: Call to undefined method C1::a2() in %s on line %d Modified: php/php-src/trunk/Zend/tests/traits/language010.phpt === --- php/php-src/trunk/Zend/tests/traits/language010.phpt2011-05-13 19:56:04 UTC (rev 310998) +++ php/php-src/trunk/Zend/tests/traits/language010.phpt2011-05-13 20:28:34 UTC (rev 310999) @@ -27,4 +27,4 @@ ? --EXPECTF-- -Fatal error: Failed to add trait method (world) to the trait table. There is probably already a trait method with the same name in %s on line %d \ No newline at end of file +Fatal error: Trait method world has not been applied, because there are collisions with other trait methods on MyClass in %s on line %d \ No newline at end of file Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2011-05-13 19:56:04 UTC (rev 310998) +++ php/php-src/trunk/Zend/zend_compile.c 2011-05-13 20:28:34 UTC (rev 310999) @@ -3662,10 +3662,13 @@ /* apply aliases which are qualified with a class name, there should not be any ambiguity */ if (aliases) { while (aliases[i]) { - if (!aliases[i]-trait_method-ce || (fn-common.scope == aliases[i]-trait_method-ce - (zend_binary_strcasecmp(aliases[i]-trait_method-method_name, + + if (/* Scope unset or equal to the function we compare to */ + (!aliases[i]-trait_method-ce || fn-common.scope == aliases[i]-trait_method-ce) + /* and, the alias applies to fn */ + (zend_binary_strcasecmp(aliases[i]-trait_method-method_name, aliases[i]-trait_method-mname_len, - fn-common.function_name, fnname_len) == 0))) { + fn-common.function_name, fnname_len) == 0)) { if (aliases[i]-alias) { fn_copy = *fn; zend_traits_duplicate_function(fn_copy, estrndup(aliases[i]-alias, aliases[i]-alias_len) TSRMLS_CC); @@ -3703,10 +3706,12 @@ if (aliases) { i = 0; while (aliases[i]) { - if ((!aliases[i]-trait_method-ce || fn-common.scope == aliases[i]-trait_method-ce) - (zend_binary_strcasecmp(aliases[i]-trait_method-method_name, - aliases[i]-trait_method-mname_len, - fn-common.function_name, fnname_len) == 0)) { + if (/* Scope unset or equal to the function we compare to */ +(!aliases[i]-trait_method-ce || fn-common.scope == aliases[i]-trait_method-ce) + /* and, the alias applies to fn */ + (zend_binary_strcasecmp(aliases[i]-trait_method-method_name, +aliases[i]-trait_method-mname_len, +
[PHP-CVS] svn: /php/php-src/trunk/ UPGRADING Zend/tests/class_exists_003.phpt Zend/tests/trait_exists_001.phpt Zend/tests/trait_exists_002.phpt Zend/tests/trait_exists_003.phpt Zend/zend_builtin_funct
gron Sun, 09 Jan 2011 19:57:41 + Revision: http://svn.php.net/viewvc?view=revisionrevision=307307 Log: Added trait_exists() [TRAITS] [DOC] - also changed class_exists() to return false for traits - added related tests, and get_declared_traits() tests in ext/s/t/co Changed paths: U php/php-src/trunk/UPGRADING U php/php-src/trunk/Zend/tests/class_exists_003.phpt A php/php-src/trunk/Zend/tests/trait_exists_001.phpt A php/php-src/trunk/Zend/tests/trait_exists_002.phpt A php/php-src/trunk/Zend/tests/trait_exists_003.phpt U php/php-src/trunk/Zend/zend_builtin_functions.c A php/php-src/trunk/ext/standard/tests/class_object/AutoTrait.inc A php/php-src/trunk/ext/standard/tests/class_object/get_declared_traits_basic_001.phpt A php/php-src/trunk/ext/standard/tests/class_object/get_declared_traits_error_001.phpt A php/php-src/trunk/ext/standard/tests/class_object/get_declared_traits_variation1.phpt A php/php-src/trunk/ext/standard/tests/class_object/trait_class_exists_variation_003.phpt A php/php-src/trunk/ext/standard/tests/class_object/trait_exists_basic_001.phpt A php/php-src/trunk/ext/standard/tests/class_object/trait_exists_error_001.phpt A php/php-src/trunk/ext/standard/tests/class_object/trait_exists_variation_001.phpt A php/php-src/trunk/ext/standard/tests/class_object/trait_exists_variation_002.phpt Modified: php/php-src/trunk/UPGRADING === --- php/php-src/trunk/UPGRADING 2011-01-09 17:40:45 UTC (rev 307306) +++ php/php-src/trunk/UPGRADING 2011-01-09 19:57:41 UTC (rev 307307) @@ -322,6 +322,7 @@ - Core: - get_declared_traits() - http_response_code() + - trait_exists() f. New global constants Modified: php/php-src/trunk/Zend/tests/class_exists_003.phpt === --- php/php-src/trunk/Zend/tests/class_exists_003.phpt 2011-01-09 17:40:45 UTC (rev 307306) +++ php/php-src/trunk/Zend/tests/class_exists_003.phpt 2011-01-09 19:57:41 UTC (rev 307307) @@ -1,5 +1,5 @@ --TEST-- -Checking if exists interface, abstract and final class +Checking if exists interface, trait, abstract and final class --FILE-- ?php @@ -9,12 +9,16 @@ final class c { } +trait d {} + var_dump(class_exists('a')); var_dump(class_exists('b')); var_dump(class_exists('c')); +var_dump(class_exists('d')); ? --EXPECT-- bool(false) bool(true) bool(true) +bool(false) Added: php/php-src/trunk/Zend/tests/trait_exists_001.phpt === --- php/php-src/trunk/Zend/tests/trait_exists_001.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/trait_exists_001.phpt 2011-01-09 19:57:41 UTC (rev 307307) @@ -0,0 +1,21 @@ +--TEST-- +Testing trait_exists() +--FILE-- +?php + +trait foo { +} + +var_dump(trait_exists('foo')); +var_dump(trait_exists(1)); +var_dump(trait_exists(NULL)); +var_dump(trait_exists(new stdClass)); + +? +--EXPECTF-- +bool(true) +bool(false) +bool(false) + +Warning: trait_exists() expects parameter 1 to be string, object given in %s on line %d +NULL Added: php/php-src/trunk/Zend/tests/trait_exists_002.phpt === --- php/php-src/trunk/Zend/tests/trait_exists_002.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/trait_exists_002.phpt 2011-01-09 19:57:41 UTC (rev 307307) @@ -0,0 +1,21 @@ +--TEST-- +Testing trait_exists() inside a namespace +--FILE-- +?php + +namespace foo; + +trait IFoo { } + +trait ITest { } + + +var_dump(trait_exists('IFoo')); +var_dump(trait_exists('foo\\IFoo')); +var_dump(trait_exists('FOO\\ITEST')); + +? +--EXPECT-- +bool(false) +bool(true) +bool(true) Added: php/php-src/trunk/Zend/tests/trait_exists_003.phpt === --- php/php-src/trunk/Zend/tests/trait_exists_003.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/trait_exists_003.phpt 2011-01-09 19:57:41 UTC (rev 307307) @@ -0,0 +1,24 @@ +--TEST-- +Checking trait_exists(): interface, trait, abstract and final class +--FILE-- +?php + +interface a { } + +abstract class b { } + +final class c { } + +trait d {} + +var_dump(trait_exists('a')); +var_dump(trait_exists('b')); +var_dump(trait_exists('c')); +var_dump(trait_exists('d')); + +? +--EXPECT-- +bool(false) +bool(false) +bool(false) +bool(true) Modified: php/php-src/trunk/Zend/zend_builtin_functions.c === --- php/php-src/trunk/Zend/zend_builtin_functions.c 2011-01-09 17:40:45 UTC (rev 307306) +++ php/php-src/trunk/Zend/zend_builtin_functions.c 2011-01-09 19:57:41 UTC (rev 307307) @@ -50,6 +50,7 @@ static ZEND_FUNCTION(property_exists); static ZEND_FUNCTION(class_exists); static
[PHP-CVS] svn: /php/php-src/trunk/Zend/ zend_compile.c
gron Mon, 20 Dec 2010 08:49:59 + Revision: http://svn.php.net/viewvc?view=revisionrevision=306489 Log: Removed dead code. # should not have been commited in the first place. Changed paths: U php/php-src/trunk/Zend/zend_compile.c Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2010-12-20 08:45:09 UTC (rev 306488) +++ php/php-src/trunk/Zend/zend_compile.c 2010-12-20 08:49:59 UTC (rev 306489) @@ -3876,7 +3876,6 @@ static void zend_do_traits_property_binding(zend_class_entry *ce TSRMLS_DC) /* {{{ */ { - /* HashTable* resulting_table; */ size_t i; zend_property_info *property_info; zend_property_info *coliding_prop; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/trunk/Zend/ tests/traits/property001.phpt tests/traits/property002.phpt tests/traits/property003.phpt tests/traits/property004.phpt tests/traits/property005.phpt zend_compi
gron Mon, 20 Dec 2010 00:52:40 + Revision: http://svn.php.net/viewvc?view=revisionrevision=306476 Log: Added strict handling of properties in traits. # This is the first attempt to implement the properties as discussed on the mailinglist. # RFC is not updated to reflect this changes, yet. Changed paths: A php/php-src/trunk/Zend/tests/traits/property001.phpt A php/php-src/trunk/Zend/tests/traits/property002.phpt A php/php-src/trunk/Zend/tests/traits/property003.phpt A php/php-src/trunk/Zend/tests/traits/property004.phpt A php/php-src/trunk/Zend/tests/traits/property005.phpt U php/php-src/trunk/Zend/zend_compile.c Added: php/php-src/trunk/Zend/tests/traits/property001.phpt === --- php/php-src/trunk/Zend/tests/traits/property001.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/property001.phpt 2010-12-20 00:52:40 UTC (rev 306476) @@ -0,0 +1,40 @@ +--TEST-- +Potentially conflicting properties should result in a strict notice. Property use is discorage for traits that are supposed to enable maintainable code reuse. Accessor methods are the language supported idiom for this. +--FILE-- +?php +error_reporting(E_ALL); + +trait THello1 { + private $foo; +} + +trait THello2 { + private $foo; +} + +echo PRE-CLASS-GUARD-TraitsTest\n; + +class TraitsTest { + use THello1; + use THello2; +} + +error_reporting(E_ALL | E_STRICT); + +echo PRE-CLASS-GUARD-TraitsTest2\n; + +class TraitsTest2 { + use THello1; + use THello2; +} + +var_dump(property_exists('TraitsTest', 'foo')); +var_dump(property_exists('TraitsTest2', 'foo')); +? +--EXPECTF-- +PRE-CLASS-GUARD-TraitsTest +PRE-CLASS-GUARD-TraitsTest2 + +Strict Standards: THello1 and THello2 define the same property ($foo) in the composition of TraitsTest2. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %s on line %d +bool(true) +bool(true) \ No newline at end of file Added: php/php-src/trunk/Zend/tests/traits/property002.phpt === --- php/php-src/trunk/Zend/tests/traits/property002.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/property002.phpt 2010-12-20 00:52:40 UTC (rev 306476) @@ -0,0 +1,32 @@ +--TEST-- +Non-conflicting properties should work just fine. +--FILE-- +?php +error_reporting(E_ALL); + +trait THello1 { + public $hello = hello; +} + +trait THello2 { + private $world = World!; +} + +class TraitsTest { + use THello1; + use THello2; + function test() { + echo $this-hello . ' ' . $this-world; + } +} + +var_dump(property_exists('TraitsTest', 'hello')); +var_dump(property_exists('TraitsTest', 'world')); + +$t = new TraitsTest; +$t-test(); +? +--EXPECTF-- +bool(true) +bool(true) +hello World! \ No newline at end of file Added: php/php-src/trunk/Zend/tests/traits/property003.phpt === --- php/php-src/trunk/Zend/tests/traits/property003.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/property003.phpt 2010-12-20 00:52:40 UTC (rev 306476) @@ -0,0 +1,30 @@ +--TEST-- +Conflicting properties with different visibility modifiers should result in a fatal error, since this indicates that the code is incompatible. +--FILE-- +?php +error_reporting(E_ALL); + +trait THello1 { + public $hello; +} + +trait THello2 { + private $hello; +} + +echo PRE-CLASS-GUARD\n; + +class TraitsTest { + use THello1; + use THello2; +} + +echo POST-CLASS-GUARD\n; + +$t = new TraitsTest; +$t-hello = foo; +? +--EXPECTF-- +PRE-CLASS-GUARD + +Fatal error: THello1 and THello2 define the same property ($hello) in the composition of TraitsTest. However, the definition differs and is considered incompatible. Class was composed in %s on line %d \ No newline at end of file Added: php/php-src/trunk/Zend/tests/traits/property004.phpt === --- php/php-src/trunk/Zend/tests/traits/property004.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/property004.phpt 2010-12-20 00:52:40 UTC (rev 306476) @@ -0,0 +1,30 @@ +--TEST-- +Conflicting properties with different initial values are considered incompatible. +--FILE-- +?php +error_reporting(E_ALL); + +trait THello1 { + public $hello = foo; +} + +trait THello2 { + private $hello = bar; +} + +echo PRE-CLASS-GUARD\n; + +class TraitsTest { + use THello1; + use THello2; + public function getHello() { + return $this-hello; + } +} + +$t = new TraitsTest; +? +--EXPECTF-- +PRE-CLASS-GUARD + +Fatal error: THello1 and THello2 define the same property ($hello) in the composition of TraitsTest. However, the definition differs and is considered incompatible. Class was composed in %s on line %d \ No newline at end of file Added:
[PHP-CVS] svn: /php/php-src/trunk/Zend/ tests/traits/bugs/case-sensitive.phpt tests/traits/conflict001.phpt tests/traits/conflict003.phpt tests/traits/error_011.phpt tests/traits/error_015.phpt tests/
gron Sun, 12 Dec 2010 16:48:02 + Revision: http://svn.php.net/viewvc?view=revisionrevision=306267 Log: Changed collision warning for Traits to fatal error. #This change is made to have all possible cases of collisions consistently handled as fatal errors. #The reason to have it fatal is that most likely something changed unexpectedly and needs urgent attention by the developer, since it will fail eventually anyway for instance because the expected method is missing in the class. #Discussed in this thread: http://marc.info/?l=php-internalsm=129155790226876 Changed paths: U php/php-src/trunk/Zend/tests/traits/bugs/case-sensitive.phpt U php/php-src/trunk/Zend/tests/traits/conflict001.phpt U php/php-src/trunk/Zend/tests/traits/conflict003.phpt U php/php-src/trunk/Zend/tests/traits/error_011.phpt U php/php-src/trunk/Zend/tests/traits/error_015.phpt U php/php-src/trunk/Zend/tests/traits/language011.phpt U php/php-src/trunk/Zend/tests/traits/methods_002.phpt U php/php-src/trunk/Zend/zend_compile.c Modified: php/php-src/trunk/Zend/tests/traits/bugs/case-sensitive.phpt === --- php/php-src/trunk/Zend/tests/traits/bugs/case-sensitive.phpt 2010-12-12 16:17:50 UTC (rev 306266) +++ php/php-src/trunk/Zend/tests/traits/bugs/case-sensitive.phpt 2010-12-12 16:48:02 UTC (rev 306267) @@ -20,6 +20,4 @@ } ? --EXPECTF-- -Warning: Trait method M1 has not been applied, because there are collisions with other trait methods on MyClass in %s on line %d - -Warning: Trait method M2 has not been applied, because there are collisions with other trait methods on MyClass in %s on line %d \ No newline at end of file +Fatal error: Trait method M1 has not been applied, because there are collisions with other trait methods on MyClass in %s on line %d Modified: php/php-src/trunk/Zend/tests/traits/conflict001.phpt === --- php/php-src/trunk/Zend/tests/traits/conflict001.phpt2010-12-12 16:17:50 UTC (rev 306266) +++ php/php-src/trunk/Zend/tests/traits/conflict001.phpt2010-12-12 16:48:02 UTC (rev 306267) @@ -22,4 +22,4 @@ } ? --EXPECTF-- -Warning: Trait method hello has not been applied, because there are collisions with other trait methods on TraitsTest in %s on line %d \ No newline at end of file +Fatal error: Trait method hello has not been applied, because there are collisions with other trait methods on TraitsTest in %s on line %d \ No newline at end of file Modified: php/php-src/trunk/Zend/tests/traits/conflict003.phpt === --- php/php-src/trunk/Zend/tests/traits/conflict003.phpt2010-12-12 16:17:50 UTC (rev 306266) +++ php/php-src/trunk/Zend/tests/traits/conflict003.phpt2010-12-12 16:48:02 UTC (rev 306267) @@ -28,6 +28,4 @@ ? --EXPECTF-- -Warning: Trait method smallTalk has not been applied, because there are collisions with other trait methods on Talker in %s on line %d - -Warning: Trait method bigTalk has not been applied, because there are collisions with other trait methods on Talker in %s on line %d \ No newline at end of file +Fatal error: Trait method smallTalk has not been applied, because there are collisions with other trait methods on Talker in %s on line %d \ No newline at end of file Modified: php/php-src/trunk/Zend/tests/traits/error_011.phpt === --- php/php-src/trunk/Zend/tests/traits/error_011.phpt 2010-12-12 16:17:50 UTC (rev 306266) +++ php/php-src/trunk/Zend/tests/traits/error_011.phpt 2010-12-12 16:48:02 UTC (rev 306267) @@ -23,6 +23,4 @@ ? --EXPECTF-- -Warning: Trait method test has not been applied, because there are collisions with other trait methods on bar in %s on line %d - -Fatal error: Call to undefined method bar::test() in %s on line %d +Fatal error: Trait method test has not been applied, because there are collisions with other trait methods on bar in %s on line %d Modified: php/php-src/trunk/Zend/tests/traits/error_015.phpt === --- php/php-src/trunk/Zend/tests/traits/error_015.phpt 2010-12-12 16:17:50 UTC (rev 306266) +++ php/php-src/trunk/Zend/tests/traits/error_015.phpt 2010-12-12 16:48:02 UTC (rev 306267) @@ -23,6 +23,4 @@ ? --EXPECTF-- -Warning: Trait method test has not been applied, because there are collisions with other trait methods on bar in %s on line %d - -Fatal error: Call to undefined method bar::test() in %s on line %d +Fatal error: Trait method test has not been applied, because there are collisions with other trait methods on bar in %s on line %d Modified: php/php-src/trunk/Zend/tests/traits/language011.phpt === ---
[PHP-CVS] svn: /php/php-src/trunk/Zend/ zend_compile.c
gron Sun, 12 Dec 2010 17:12:29 + Revision: http://svn.php.net/viewvc?view=revisionrevision=306272 Log: Changed E_ERROR to E_COMPILE_ERROR for Trait compilation errors. #Thanks for catching this Kalle. Changed paths: U php/php-src/trunk/Zend/zend_compile.c Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2010-12-12 17:09:20 UTC (rev 306271) +++ php/php-src/trunk/Zend/zend_compile.c 2010-12-12 17:12:29 UTC (rev 306272) @@ -3459,7 +3459,7 @@ if (zend_hash_quick_find(ce-function_table, hash_key-arKey, hash_key-nKeyLength, hash_key-h, (void **)class_fn) == FAILURE || class_fn-common.scope != ce) { - zend_error(E_ERROR, Trait method %s has not been applied, because there are collisions with other trait methods on %s, fn-common.function_name, ce-name); + zend_error(E_COMPILE_ERROR, Trait method %s has not been applied, because there are collisions with other trait methods on %s, fn-common.function_name, ce-name); } zend_function_dtor(fn); @@ -3468,7 +3468,7 @@ } else { /* Add it to result function table */ if (zend_hash_quick_add(resulting_table, hash_key-arKey, hash_key-nKeyLength, hash_key-h, fn, sizeof(zend_function), NULL)==FAILURE) { - zend_error(E_ERROR, Trait method %s has not been applied, because failure occured during updating resulting trait method table, fn-common.function_name); + zend_error(E_COMPILE_ERROR, Trait method %s has not been applied, because failure occured during updating resulting trait method table, fn-common.function_name); } } @@ -3632,7 +3632,7 @@ zend_traits_duplicate_function(fn_copy, estrdup(fn-common.function_name) TSRMLS_CC); if (zend_hash_quick_update(ce-function_table, hash_key-arKey, hash_key-nKeyLength, hash_key-h, fn_copy, sizeof(zend_function), (void**)fn_copy_p)==FAILURE) { - zend_error(E_ERROR, Trait method %s has not been applied, because failure occured during updating class method table, hash_key-arKey); + zend_error(E_COMPILE_ERROR, Trait method %s has not been applied, because failure occured during updating class method table, hash_key-arKey); } _ADD_MAGIC_METHOD(ce, hash_key-arKey, hash_key-nKeyLength, fn_copy_p); @@ -3687,7 +3687,7 @@ lcname = zend_str_tolower_dup(aliases[i]-alias, lcname_len); if (zend_hash_add(target, lcname, lcname_len+1, fn_copy, sizeof(zend_function), NULL)==FAILURE) { - zend_error(E_ERROR, Failed to add aliased trait method (%s) to the trait table. There is probably already a trait method with the same name, fn_copy.common.function_name); + zend_error(E_COMPILE_ERROR, Failed to add aliased trait method (%s) to the trait table. There is probably already a trait method with the same name, fn_copy.common.function_name); } /* aliases[i]-function = fn_copy; */ efree(lcname); @@ -3725,7 +3725,7 @@ } if (zend_hash_add(target, lcname, fnname_len+1, fn_copy, sizeof(zend_function), NULL)==FAILURE) { - zend_error(E_ERROR, Failed to add trait method (%s) to the trait table. There is probably already a trait method with the same name, fn_copy.common.function_name); + zend_error(E_COMPILE_ERROR, Failed to add trait method (%s) to the trait table. There is probably already a trait method with the same name, fn_copy.common.function_name); } } @@ -3799,7 +3799,7 @@ char* lcname = zend_str_tolower_dup(precedences[i]-trait_method-method_name, lcname_len); if (zend_hash_add(exclude_table, lcname, lcname_len, NULL, 0, NULL)==FAILURE) { - zend_error(E_ERROR, Failed to evaluate a trait precedence (%s). Method of trait %s was defined to be excluded multiple times, precedences[i]-trait_method-method_name, trait-name); + zend_error(E_COMPILE_ERROR, Failed to evaluate a trait precedence (%s). Method of trait %s was defined to be excluded multiple times, precedences[i]-trait_method-method_name, trait-name); }
[PHP-CVS] svn: /php/php-src/trunk/Zend/ zend_compile.h
gron Wed, 01 Dec 2010 15:20:11 + Revision: http://svn.php.net/viewvc?view=revisionrevision=305890 Log: Removed old commented function prototypes. # Was referring to old trait-related code that is long gone Changed paths: U php/php-src/trunk/Zend/zend_compile.h Modified: php/php-src/trunk/Zend/zend_compile.h === --- php/php-src/trunk/Zend/zend_compile.h 2010-12-01 15:02:24 UTC (rev 305889) +++ php/php-src/trunk/Zend/zend_compile.h 2010-12-01 15:20:11 UTC (rev 305890) @@ -505,8 +505,6 @@ void zend_do_implements_trait(znode *interface_znode /*, znode* aliases */ TSRMLS_DC); ZEND_API void zend_do_implement_trait(zend_class_entry *ce, zend_class_entry *trait TSRMLS_DC); ZEND_API void zend_do_bind_traits(zend_class_entry *ce TSRMLS_DC); -/* void zend_do_binds_traits(TSRMLS_D); */ -/* ZEND_API void zend_do_add_trait_preparative_to_class(zend_class_entry *ce, zend_class_entry *trait TSRMLS_DC); */ void zend_prepare_trait_precedence(znode *result, znode *method_reference, znode *trait_list TSRMLS_DC); void zend_prepare_reference(znode *result, znode *class_name, znode *method_name TSRMLS_DC); void zend_prepare_trait_alias(znode *result, znode *method_reference, znode *modifiers, znode *alias TSRMLS_DC); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/trunk/Zend/tests/traits/ static_001.phpt static_002.phpt static_003.phpt static_004.phpt static_forward_static_call.phpt static_get_called_class.phpt
gron Wed, 17 Nov 2010 23:05:20 + Revision: http://svn.php.net/viewvc?view=revisionrevision=305473 Log: Added tests to for static support of traits. # This was not tested and documented yet. # Updated documentation in the RFC http://wiki.php.net/rfc/horizontalreuse Changed paths: A php/php-src/trunk/Zend/tests/traits/static_001.phpt A php/php-src/trunk/Zend/tests/traits/static_002.phpt A php/php-src/trunk/Zend/tests/traits/static_003.phpt A php/php-src/trunk/Zend/tests/traits/static_004.phpt A php/php-src/trunk/Zend/tests/traits/static_forward_static_call.phpt A php/php-src/trunk/Zend/tests/traits/static_get_called_class.phpt Added: php/php-src/trunk/Zend/tests/traits/static_001.phpt === --- php/php-src/trunk/Zend/tests/traits/static_001.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/static_001.phpt 2010-11-17 23:05:20 UTC (rev 305473) @@ -0,0 +1,22 @@ +--TEST-- +Traits with static methods. +--CREDITS-- +Simas Toleikis sim...@gmail.com +--FILE-- +?php + + trait TestTrait { + public static function test() { + return 'Test'; + } + } + + class A { + use TestTrait; + } + + echo A::test(); + +? +--EXPECT-- +Test \ No newline at end of file Added: php/php-src/trunk/Zend/tests/traits/static_002.phpt === --- php/php-src/trunk/Zend/tests/traits/static_002.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/static_002.phpt 2010-11-17 23:05:20 UTC (rev 305473) @@ -0,0 +1,23 @@ +--TEST-- +Traits with static methods referenced using variable. +--CREDITS-- +Simas Toleikis sim...@gmail.com +--FILE-- +?php + + trait TestTrait { + public static function test() { + return 'Test'; + } + } + + class A { + use TestTrait; + } + + $class = A; + echo $class::test(); + +? +--EXPECT-- +Test \ No newline at end of file Added: php/php-src/trunk/Zend/tests/traits/static_003.phpt === --- php/php-src/trunk/Zend/tests/traits/static_003.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/static_003.phpt 2010-11-17 23:05:20 UTC (rev 305473) @@ -0,0 +1,27 @@ +--TEST-- +Traits with late static bindings. +--CREDITS-- +Simas Toleikis sim...@gmail.com +--FILE-- +?php + + trait TestTrait { + public static function test() { + return static::$test; + } + } + + class A { + use TestTrait; + protected static $test = Test A; + } + + class B extends A { + protected static $test = Test B; + } + + echo B::test(); + +? +--EXPECT-- +Test B \ No newline at end of file Added: php/php-src/trunk/Zend/tests/traits/static_004.phpt === --- php/php-src/trunk/Zend/tests/traits/static_004.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/static_004.phpt 2010-11-17 23:05:20 UTC (rev 305473) @@ -0,0 +1,22 @@ +--TEST-- +Traits with __callStatic magic method. +--CREDITS-- +Simas Toleikis sim...@gmail.com +--FILE-- +?php + + trait TestTrait { + public static function __callStatic($name, $arguments) { + return $name; + } + } + + class A { + use TestTrait; + } + + echo A::Test(); + +? +--EXPECT-- +Test \ No newline at end of file Added: php/php-src/trunk/Zend/tests/traits/static_forward_static_call.phpt === --- php/php-src/trunk/Zend/tests/traits/static_forward_static_call.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/static_forward_static_call.phpt 2010-11-17 23:05:20 UTC (rev 305473) @@ -0,0 +1,28 @@ +--TEST-- +Traits and forward_static_call(). +--CREDITS-- +Simas Toleikis sim...@gmail.com +--FILE-- +?php + + trait TestTrait { + public static function test() { + return 'Forwarded '.forward_static_call(array('A', 'test')); + } + } + + class A { + public static function test() { + return Test A; + } + } + + class B extends A { + use TestTrait; + } + + echo B::test(); + +? +--EXPECT-- +Forwarded Test A \ No newline at end of file Added: php/php-src/trunk/Zend/tests/traits/static_get_called_class.phpt === --- php/php-src/trunk/Zend/tests/traits/static_get_called_class.phpt
[PHP-CVS] svn: /php/php-src/trunk/ NEWS
gron Sun, 01 Aug 2010 20:53:32 + Revision: http://svn.php.net/viewvc?view=revisionrevision=301768 Log: Added Traits to the NEWS file. #There doesn't seem to be a consitent ordering, #so I put it in front of the list, since it is a major language addition. Hope thats ok. Changed paths: U php/php-src/trunk/NEWS Modified: php/php-src/trunk/NEWS === --- php/php-src/trunk/NEWS 2010-08-01 18:19:09 UTC (rev 301767) +++ php/php-src/trunk/NEWS 2010-08-01 20:53:32 UTC (rev 301768) @@ -30,6 +30,7 @@ - Added an optimization which saves memory and emalloc/efree calls for empty HashTables (Stas, Dmitry) +- Added support for Traits. (Stefan) - Added array dereferencing support. (Felipe) - Added DTrace support. (David Soria Parra) - Added Tokyo Cabinet abstract DB support to ext/dba. (Michael Maclean) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/trunk/Zend/ tests/traits/language012.phpt tests/traits/language013.phpt zend_closures.c zend_compile.c zend_variables.c zend_variables.h
gron Tue, 08 Jun 2010 15:56:36 + Revision: http://svn.php.net/viewvc?view=revisionrevision=300283 Log: Fixed issue with statics in traits. #Please review this change, I moved the routine which copies statics from the closure code to zend_variables.c #Please also have a look to check whether the TSRMLS_DC is correct, and whether it fits with the rest in zend_variables, because there you are using some macro magic and I am not exactly sure what the reason is for that. Changed paths: A php/php-src/trunk/Zend/tests/traits/language012.phpt A php/php-src/trunk/Zend/tests/traits/language013.phpt U php/php-src/trunk/Zend/zend_closures.c U php/php-src/trunk/Zend/zend_compile.c U php/php-src/trunk/Zend/zend_variables.c U php/php-src/trunk/Zend/zend_variables.h Added: php/php-src/trunk/Zend/tests/traits/language012.phpt === --- php/php-src/trunk/Zend/tests/traits/language012.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/language012.phpt2010-06-08 15:56:36 UTC (rev 300283) @@ -0,0 +1,27 @@ +--TEST-- +Statics should work in traits, too. +--FILE-- +?php +error_reporting(E_ALL); + +trait Counter { + public function inc() { + static $c = 0; + $c = $c + 1; + echo $c\n; + } +} + + +class C1 { + use Counter; +} + +$o = new C1(); +$o-inc(); +$o-inc(); + +? +--EXPECTF-- +1 +2 Added: php/php-src/trunk/Zend/tests/traits/language013.phpt === --- php/php-src/trunk/Zend/tests/traits/language013.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/language013.phpt2010-06-08 15:56:36 UTC (rev 300283) @@ -0,0 +1,37 @@ +--TEST-- +Statics work like expected for language-based copy'n'paste. No link between methods from the same trait. +--FILE-- +?php +error_reporting(E_ALL); + +trait Counter { + public function inc() { + static $c = 0; + $c = $c + 1; + echo $c\n; + } +} + + +class C1 { + use Counter; +} + +class C2 { + use Counter; +} + +$o = new C1(); +$o-inc(); +$o-inc(); + +$p = new C2(); +$p-inc(); +$p-inc(); + +? +--EXPECTF-- +1 +2 +1 +2 Modified: php/php-src/trunk/Zend/zend_closures.c === --- php/php-src/trunk/Zend/zend_closures.c 2010-06-08 15:47:51 UTC (rev 300282) +++ php/php-src/trunk/Zend/zend_closures.c 2010-06-08 15:56:36 UTC (rev 300283) @@ -398,43 +398,6 @@ } /* }}} */ -static int zval_copy_static_var(zval **p TSRMLS_DC, int num_args, va_list args, zend_hash_key *key) /* {{{ */ -{ - HashTable *target = va_arg(args, HashTable*); - zend_bool is_ref; - - if (Z_TYPE_PP(p) (IS_LEXICAL_VAR|IS_LEXICAL_REF)) { - is_ref = Z_TYPE_PP(p) IS_LEXICAL_REF; - - if (!EG(active_symbol_table)) { - zend_rebuild_symbol_table(TSRMLS_C); - } - if (zend_hash_quick_find(EG(active_symbol_table), key-arKey, key-nKeyLength, key-h, (void **) p) == FAILURE) { - if (is_ref) { - zval *tmp; - - ALLOC_INIT_ZVAL(tmp); - Z_SET_ISREF_P(tmp); - zend_hash_quick_add(EG(active_symbol_table), key-arKey, key-nKeyLength, key-h, tmp, sizeof(zval*), (void**)p); - } else { - p = EG(uninitialized_zval_ptr); - zend_error(E_NOTICE,Undefined variable: %s, key-arKey); - } - } else { - if (is_ref) { - SEPARATE_ZVAL_TO_MAKE_IS_REF(p); - } else if (Z_ISREF_PP(p)) { - SEPARATE_ZVAL(p); - } - } - } - if (zend_hash_quick_add(target, key-arKey, key-nKeyLength, key-h, p, sizeof(zval*), NULL) == SUCCESS) { - Z_ADDREF_PP(p); - } - return ZEND_HASH_APPLY_KEEP; -} -/* }}} */ - ZEND_API void zend_create_closure(zval *res, zend_function *func, zend_class_entry *scope, zval *this_ptr TSRMLS_DC) /* {{{ */ { zend_closure *closure; Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2010-06-08 15:47:51 UTC (rev 300282) +++ php/php-src/trunk/Zend/zend_compile.c 2010-06-08 15:56:36 UTC (rev 300283) @@ -3476,8 +3476,9 @@ zval tmpZval; ALLOC_HASHTABLE(tmpHash); - zend_hash_init(tmpHash, 2, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(tmpHash, fe-op_array.static_variables, ZVAL_COPY_CTOR, tmpZval, sizeof(zval)); + zend_hash_init(tmpHash,
[PHP-CVS] svn: /php/php-src/trunk/Zend/ zend_compile.c
gron Mon, 03 May 2010 22:08:09 + Revision: http://svn.php.net/viewvc?view=revisionrevision=298935 Log: Changed naming of traits-related helper functions (suggested by Derick), added missing static qualifiers. Changed paths: U php/php-src/trunk/Zend/zend_compile.c Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2010-05-03 22:08:06 UTC (rev 298934) +++ php/php-src/trunk/Zend/zend_compile.c 2010-05-03 22:08:09 UTC (rev 298935) @@ -3231,7 +3231,7 @@ } /* }}} */ -static int _merge_functions(zend_function *fn TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ +static int zend_traits_merge_functions(zend_function *fn TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { size_t current; size_t i; @@ -3320,7 +3320,7 @@ /* {{{ Originates from php_runkit_function_copy_ctor Duplicate structures in an op_array where necessary to make an outright duplicate */ -void _duplicate_function(zend_function *fe, char *newname) +static void zend_traits_duplicate_function(zend_function *fe, char *newname) { zend_literal *literals_copy; zend_compiled_variable *dupvars; @@ -3405,7 +3405,7 @@ } /* */ -static int _merge_functions_to_class(zend_function *fn TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +static int zend_traits_merge_functions_to_class(zend_function *fn TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) { zend_class_entry *ce = va_arg(args, zend_class_entry*); int add = 0; @@ -3465,7 +3465,7 @@ return ZEND_HASH_APPLY_REMOVE; } -static int _copy_functions(zend_function *fn TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) { HashTable* target; zend_trait_alias** aliases; @@ -3492,7 +3492,7 @@ fn-common.function_name, fnname_len) == 0)) { if (aliases[i]-alias) { fn_copy = *fn; - _duplicate_function(fn_copy, estrndup(aliases[i]-alias, aliases[i]-alias_len)); + zend_traits_duplicate_function(fn_copy, estrndup(aliases[i]-alias, aliases[i]-alias_len)); if (aliases[i]-modifiers) { /* if it is 0, no modifieres has been changed */ fn_copy.common.fn_flags = aliases[i]-modifiers; @@ -3521,7 +3521,7 @@ if (zend_hash_find(exclude_table, lcname, fnname_len, dummy) == FAILURE) { /* is not in hashtable, thus, function is not to be excluded */ fn_copy = *fn; - _duplicate_function(fn_copy, estrndup(fn-common.function_name, fnname_len)); + zend_traits_duplicate_function(fn_copy, estrndup(fn-common.function_name, fnname_len)); /* apply aliases which are not qualified by a class name, or which have not alias name, just setting visibility */ /* TODO: i am still not sure, that there will be no ambigousities... */ @@ -3538,7 +3538,7 @@ char* lcname2; zend_function fn_copy2 = *fn; - _duplicate_function(fn_copy2, estrndup(aliases[i]-alias, aliases[i]-alias_len)); + zend_traits_duplicate_function(fn_copy2, estrndup(aliases[i]-alias, aliases[i]-alias_len)); if (aliases[i]-modifiers) { /* if it is 0, no modifieres has been changed */ fn_copy2.common.fn_flags = aliases[i]-modifiers; @@ -3583,12 +3583,12 @@ /** * Copies function table entries to target function table with applied aliasing */ -void copy_trait_function_table(HashTable *target, HashTable *source, zend_trait_alias** aliases, HashTable* exclude_table TSRMLS_DC) { - zend_hash_apply_with_arguments(source TSRMLS_CC, (apply_func_args_t)_copy_functions, 3, /* 3 is number of args for apply_func */ +static void zend_traits_copy_trait_function_table(HashTable *target, HashTable *source, zend_trait_alias** aliases, HashTable* exclude_table TSRMLS_DC) { + zend_hash_apply_with_arguments(source TSRMLS_CC, (apply_func_args_t)zend_traits_copy_functions, 3, /* 3 is number of args for apply_func */ target, aliases, exclude_table); } -void init_trait_structures(zend_class_entry *ce TSRMLS_DC) /* {{{ */ +static void zend_traits_init_trait_structures(zend_class_entry *ce TSRMLS_DC) /* {{{ */ { size_t i,
[PHP-CVS] svn: /php/php-src/trunk/Zend/ zend_compile.c zend_opcode.c
gron Sun, 02 May 2010 16:32:25 + Revision: http://svn.php.net/viewvc?view=revisionrevision=298877 Log: Refactored part of the Traits implementation. # - renamed php_runkit_function_copy_ctor to _duplicate_function # REM: runkit does not compile with trunk at the moment, fixing it would introduce even more version #ifs, don't know what the best way is to fix it # - extracted traits related stuff from destroy_zend_class into _destroy_zend_class_traits_info # - need to investigate implementation/handling of internal classes further before enabling internal traits Changed paths: U php/php-src/trunk/Zend/zend_compile.c U php/php-src/trunk/Zend/zend_opcode.c Modified: php/php-src/trunk/Zend/zend_compile.c === --- php/php-src/trunk/Zend/zend_compile.c 2010-05-02 15:38:31 UTC (rev 298876) +++ php/php-src/trunk/Zend/zend_compile.c 2010-05-02 16:32:25 UTC (rev 298877) @@ -3321,9 +3321,9 @@ else if (IS_EQUAL(mname, mname_len, unserialize_func))(ce)-unserialize_func = (fe); \ } -/* {{{ php_runkit_function_copy_ctor +/* {{{ Originates from php_runkit_function_copy_ctor Duplicate structures in an op_array where necessary to make an outright duplicate */ -void php_runkit_function_copy_ctor(zend_function *fe, char *newname) +void _duplicate_function(zend_function *fe, char *newname) { zend_literal *literals_copy; zend_compiled_variable *dupvars; @@ -3497,7 +3497,7 @@ fn-common.function_name, fnname_len) == 0)) { if (aliases[i]-alias) { fn_copy = *fn; - php_runkit_function_copy_ctor(fn_copy, estrndup(aliases[i]-alias, aliases[i]-alias_len)); + _duplicate_function(fn_copy, estrndup(aliases[i]-alias, aliases[i]-alias_len)); if (aliases[i]-modifiers) { /* if it is 0, no modifieres has been changed */ fn_copy.common.fn_flags = aliases[i]-modifiers; @@ -3527,7 +3527,7 @@ if (zend_hash_find(exclude_table, lcname, lcname_len, dummy) == FAILURE) { /* is not in hashtable, thus, function is not to be excluded */ fn_copy = *fn; - php_runkit_function_copy_ctor(fn_copy, estrndup(fn-common.function_name, fnname_len)); + _duplicate_function(fn_copy, estrndup(fn-common.function_name, fnname_len)); /* apply aliases which are not qualified by a class name, or which have not alias name, just setting visibility */ /* TODO: i am still not sure, that there will be no ambigousities... */ @@ -3543,7 +3543,7 @@ zend_uint lcname2_len; char* lcname2; zend_function fn_copy2 = *fn; - php_runkit_function_copy_ctor(fn_copy2, estrndup(aliases[i]-alias, aliases[i]-alias_len)); + _duplicate_function(fn_copy2, estrndup(aliases[i]-alias, aliases[i]-alias_len)); if (aliases[i]-modifiers) { /* if it is 0, no modifieres has been changed */ fn_copy2.common.fn_flags = aliases[i]-modifiers; Modified: php/php-src/trunk/Zend/zend_opcode.c === --- php/php-src/trunk/Zend/zend_opcode.c2010-05-02 15:38:31 UTC (rev 298876) +++ php/php-src/trunk/Zend/zend_opcode.c2010-05-02 16:32:25 UTC (rev 298877) @@ -176,6 +176,55 @@ return 0; } +void _destroy_zend_class_traits_info(zend_class_entry *ce) +{ + if (ce-num_traits 0 ce-traits) { + efree(ce-traits); + } + + if (ce-trait_aliases) { + size_t i = 0; + while (ce-trait_aliases[i]) { + if (ce-trait_aliases[i]-trait_method) { + if (ce-trait_aliases[i]-trait_method-method_name) { + efree(ce-trait_aliases[i]-trait_method-method_name); + } + if (ce-trait_aliases[i]-trait_method-class_name) { + efree(ce-trait_aliases[i]-trait_method-class_name); + } + efree(ce-trait_aliases[i]-trait_method); + } + + if (ce-trait_aliases[i]-alias) { + efree(ce-trait_aliases[i]-alias); + } + + efree(ce-trait_aliases[i]); + i++;
Re: [PHP-CVS] svn: /php/php-src/trunk/Zend/ zend_compile.c zend_opcode.c
Hi Derick: On 02 May 2010, at 19:12, Derick Rethans wrote: Is there a reason why you named this to something with a _ at the start? AFAIK we've never done this, and instead prefer php_ (or in this case, zend_ ) I have named all internal helper functions this way in the traits related code. Its a function which is only used in that .c file and not exposed by the header. What is the usual naming convention for that case? Thanks Stefan Derick -- http://derickrethans.nl | http://xdebug.org Like Xdebug? Consider a donation: http://xdebug.org/donate.php twitter: @derickr and @xdebug -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] svn: /php/php-src/trunk/Zend/ zend.h zend_compile.c zend_compile.h zend_execute_API.c zend_language_parser.y zend_language_scanner.c zend_language_scanner.l zend_language_scanner_defs.h
Hi Kalle: On 23 Apr 2010, at 01:04, Kalle Sommer Nielsen wrote: Revision: http://svn.php.net/viewvc?view=revisionrevision=298348 Log: Implemented Traits for PHP as proposed in the RFC [TRAITS] You seem to use C++ style comments, these are not C89 compatible and should be /* */ instead. Thanks to Felipe that seems to be already fixed :) Thanks Stefan -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/trunk/Zend/tests/traits/ language003.phpt language004.phpt language005.phpt language009.phpt
gron Thu, 22 Apr 2010 21:56:55 + Revision: http://svn.php.net/viewvc?view=revisionrevision=298347 Log: Changed the exclusion keyword from 'instead' to 'insteadof'. [TRAITS] #That was suggested several times already, but am still not sure whether that really reads better. #Especially since only the trait is mentioned, since the method name would be duplicated anyway. Changed paths: U php/php-src/trunk/Zend/tests/traits/language003.phpt U php/php-src/trunk/Zend/tests/traits/language004.phpt U php/php-src/trunk/Zend/tests/traits/language005.phpt U php/php-src/trunk/Zend/tests/traits/language009.phpt Modified: php/php-src/trunk/Zend/tests/traits/language003.phpt === --- php/php-src/trunk/Zend/tests/traits/language003.phpt2010-04-22 21:50:53 UTC (rev 298346) +++ php/php-src/trunk/Zend/tests/traits/language003.phpt2010-04-22 21:56:55 UTC (rev 298347) @@ -18,7 +18,7 @@ class MyHelloWorld { use Hello, World { - Hello::saySomething instead World; + Hello::saySomething insteadof World; } } Modified: php/php-src/trunk/Zend/tests/traits/language004.phpt === --- php/php-src/trunk/Zend/tests/traits/language004.phpt2010-04-22 21:50:53 UTC (rev 298346) +++ php/php-src/trunk/Zend/tests/traits/language004.phpt2010-04-22 21:56:55 UTC (rev 298347) @@ -18,7 +18,7 @@ class MyHelloWorld { use Hello, World { - Hello::saySomething instead World; + Hello::saySomething insteadof World; World::saySomething as sayWorld; } } Modified: php/php-src/trunk/Zend/tests/traits/language005.phpt === --- php/php-src/trunk/Zend/tests/traits/language005.phpt2010-04-22 21:50:53 UTC (rev 298346) +++ php/php-src/trunk/Zend/tests/traits/language005.phpt2010-04-22 21:56:55 UTC (rev 298347) @@ -24,8 +24,8 @@ class Talker { use A, B { - B::smallTalk instead A; - A::bigTalk instead B; + B::smallTalk insteadof A; + A::bigTalk insteadof B; B::bigTalk as talk; } } Modified: php/php-src/trunk/Zend/tests/traits/language009.phpt === --- php/php-src/trunk/Zend/tests/traits/language009.phpt2010-04-22 21:50:53 UTC (rev 298346) +++ php/php-src/trunk/Zend/tests/traits/language009.phpt2010-04-22 21:56:55 UTC (rev 298347) @@ -24,7 +24,7 @@ class Foo { use C, A, B { - B::foo instead A, C; + B::foo insteadof A, C; } } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/trunk/Zend/tests/ traits/bugs/abstract-methods01.phpt traits/bugs/abstract-methods02.phpt traits/bugs/abstract-methods03.phpt traits/bugs/abstract-methods04.phpt traits/bug
gron Thu, 15 Apr 2010 21:39:20 + Revision: http://svn.php.net/viewvc?view=revisionrevision=298062 Log: Added traits test cases. No engine changes for now. [TRAITS] #Getting accustomed to the infrastructure. #Any comments are welcome, especially with regard to syntax and keywords. Changed paths: A php/php-src/trunk/Zend/tests/traits/ A php/php-src/trunk/Zend/tests/traits/bugs/ A php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods01.phpt A php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods02.phpt A php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods03.phpt A php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods04.phpt A php/php-src/trunk/Zend/tests/traits/bugs/alias-semantics.phpt A php/php-src/trunk/Zend/tests/traits/bugs/case-sensitive.phpt A php/php-src/trunk/Zend/tests/traits/bugs/interfaces.phpt A php/php-src/trunk/Zend/tests/traits/bugs/missing-trait.phpt A php/php-src/trunk/Zend/tests/traits/bugs/overridding-conflicting-methods.phpt A php/php-src/trunk/Zend/tests/traits/conflict001.phpt A php/php-src/trunk/Zend/tests/traits/conflict002.phpt A php/php-src/trunk/Zend/tests/traits/conflict003.phpt A php/php-src/trunk/Zend/tests/traits/flattening001.phpt A php/php-src/trunk/Zend/tests/traits/flattening002.phpt A php/php-src/trunk/Zend/tests/traits/flattening003.phpt A php/php-src/trunk/Zend/tests/traits/inheritance001.phpt A php/php-src/trunk/Zend/tests/traits/inheritance002.phpt A php/php-src/trunk/Zend/tests/traits/inheritance003.phpt A php/php-src/trunk/Zend/tests/traits/language001.phpt A php/php-src/trunk/Zend/tests/traits/language002.phpt A php/php-src/trunk/Zend/tests/traits/language003.phpt A php/php-src/trunk/Zend/tests/traits/language004.phpt A php/php-src/trunk/Zend/tests/traits/language005.phpt A php/php-src/trunk/Zend/tests/traits/language006.phpt A php/php-src/trunk/Zend/tests/traits/language007.phpt A php/php-src/trunk/Zend/tests/traits/language008a.phpt A php/php-src/trunk/Zend/tests/traits/language008b.phpt A php/php-src/trunk/Zend/tests/traits/language009.phpt A php/php-src/trunk/Zend/tests/traits/language010.phpt A php/php-src/trunk/Zend/tests/traits/language011.phpt Added: php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods01.phpt === --- php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods01.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods01.phpt 2010-04-15 21:39:20 UTC (rev 298062) @@ -0,0 +1,19 @@ +--TEST-- +Abstract Trait Methods should behave like common abstract methods. +--FILE-- +?php +error_reporting(E_ALL); + +trait THello { + public abstract function hello(); +} + +class TraitsTest { + use THello; +} + +$test = new TraitsTest(); +$test-hello(); +? +--EXPECTF-- +Fatal error: Class %s contains %d abstract method and must therefore be declared abstract or implement the remaining methods (%s) in %s on line %d \ No newline at end of file Added: php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods02.phpt === --- php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods02.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods02.phpt 2010-04-15 21:39:20 UTC (rev 298062) @@ -0,0 +1,26 @@ +--TEST-- +Abstract Trait Methods should behave like common abstract methods. +--FILE-- +?php +error_reporting(E_ALL); + +trait THello { + public abstract function hello(); +} + +trait THelloImpl { + public function hello() { +echo 'Hello'; + } +} + +class TraitsTest { + use THello; + use THelloImpl; +} + +$test = new TraitsTest(); +$test-hello(); +? +--EXPECTF-- +Hello \ No newline at end of file Added: php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods03.phpt === --- php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods03.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods03.phpt 2010-04-15 21:39:20 UTC (rev 298062) @@ -0,0 +1,22 @@ +--TEST-- +Abstract Trait Methods should behave like common abstract methods. +--FILE-- +?php +error_reporting(E_ALL); + +trait THello { + public abstract function hello(); +} + +class TraitsTest { + use THello; + public function hello() { +echo 'Hello'; + } +} + +$test = new TraitsTest(); +$test-hello(); +? +--EXPECTF-- +Hello \ No newline at end of file Added: php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods04.phpt === --- php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods04.phpt (rev 0) +++