Edit report at https://bugs.php.net/bug.php?id=62994&edit=1

 ID:                 62994
 Comment by:         larue...@php.net
 Reported by:        reeze dot xia at gmail dot com
 Summary:            Disallow some magic methods been generators
 Status:             Assigned
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
 PHP Version:        master-Git-2012-09-02 (Git)
 Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

it's not about magic methods, it's about the calling to user function in 
internal 
should be changed properly.

I don't think disallow is a good solution. 

nikic, cannot yield simply be considered as return in such situation ?


Previous Comments:
------------------------------------------------------------------------
[2012-09-02 07:46:53] reeze dot xia at gmail dot com

Description:
------------
magic method are called in a special way, if those methods
was defined as generator, most of them will not work as expected.

We could disallow them when compiling.


Test script:
---------------
class A {
     public function __construct(array $data) {
           $this->initData = $data;
           // maybe more initialization...

           var_dump($this->initData);
           foreach$(this->initData as $v) {
               yield $v;
           }
     }
}

$a = new A(array(1, 2)); //  constructor didn't get called.

so does the that magic methods:
http://www.php.net/manual/en/language.oop5.magic.php

most of them are meanning less if they are generators.
*some of them* maybe useful if they return value but not void.


Those could be allowed: __call(), __callStatic(), __get(), __invoke()

but those seems meaningless to be generators
__construct(), __destruct(), __set(), __isset(), __unset(), __sleep(), 
__wakeup(), __toString(), __set_state() and __clone(), 




------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62994&edit=1

Reply via email to