php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #60208 Document behavior of magic methods when called inside another magic method
Submitted: 2011-11-03 12:14 UTC Modified: 2017-01-28 11:35 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: gtisza at gmail dot com Assigned:
Status: Open Package: Class/Object related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2011-11-03 12:14 UTC] gtisza at gmail dot com
Description:
------------
There seems to be a safeguard in PHP5 against infinite magic method recursion in __get etc., but this is totally missing from the documentation ( php.net/manual/en/language.oop5.overloading.php ), making the more complex uses of setters/getters very fragile.

A few questions I would expect to be answered in such a documentation:
* does the magic method get fired when I use overloading inside a magic method of the same type? (e.g. will $val = $this->bar inside __get('bar') call  __get('bar') again?)
* does the magic method get fired when I use overloading inside a magic method of another type (e.g. will $val = $this->bar inside __isset('bar') call __get('bar')? Looks like it doesn't, which seems counterintuitive to me.)
* does the magic method get fired when I use overloading inside a magic method, but call that magic method manually? (ie. does it matter whether I call the magic method with $this->bar or with $this->__get('bar')?)
* does it matter whether the magic method is present in the call chain, or just the current method matters? Eg. in this class:

<?php
class Foo {
  function __isset($name) {
    $val = $this->bar('name');
    return isset($val);
  }
  function bar($name) {
    return $this->$name;
  }
}
?>

will isset($foo->bar) call Foo::__get('bar') or not?


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-28 11:35 UTC] cmb@php.net
-Package: Documentation problem +Package: Class/Object related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC