Edit report at https://bugs.php.net/bug.php?id=62994&edit=1
ID: 62994 Updated by: larue...@php.net Reported by: reeze dot xia at gmail dot com Summary: Disallow some magic methods been generators Status: Not a bug Type: Feature/Change Request Package: Scripting Engine problem PHP Version: master-Git-2012-09-02 (Git) Block user comment: N Private report: N New Comment: like: $a = new A; foreach ($a->__construct() as $v) { } since we don't disallow call to __construct(magic methods) directly(although I don't like this). Previous Comments: ------------------------------------------------------------------------ [2012-09-02 08:00:39] larue...@php.net hmm, after a test, I found I misunderstood your mean about "not work as expected." I think this is definitely a wrong usage... there is nothing wrong with generators. disallowing make no sense at all. ------------------------------------------------------------------------ [2012-09-02 07:55:23] larue...@php.net 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 ? ------------------------------------------------------------------------ [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