Все вопросы: [magic-methods]
11 вопросов
__call() function in CakePHP controllers?
is __call() function available in CakePHP's controllers? I used this function in Zend Framework. class UsersController extends AppController { function home(){ /*some action*/ } function __call($m, $p){ print_r($m); print_r($p); } } I'm getting error li...
PHP's magic method __call on subclasses
My situation is best described with a bit of code: class Foo { function bar () { echo "called Foo::bar()"; } } class SubFoo extends Foo { function __call($func) { if ($func == "bar") { echo "intercepted bar()!"; } } } $subFoo = new SubFoo(); ...
Difference between __str__ and __repr__?
What is the difference between __str__ and __repr__ in Python?
Where is the Python documentation for the special methods? (__init__, __new__, __len__, ...)
Where is a complete list of the special double-underscore/dunder methods that can be used in classes? (e.g., __init__, __new__, __len__, __add__)
How does Scala's apply() method magic work?
In Scala, if I define a method called apply in a class or a top-level object, that method will be called whenever I append a pair a parentheses to an instance of that class, and put the appropriate arguments for apply() in between them. For example: class Foo(x: Int) { def apply(y: Int) = { ...
Best Practices for __get() and __set()
Stemming from this question on using __get() and __set() to access private variables, I'd like to get the input on how they are used in general. I am wondering when or where would be the best time to use a overloading function, and where you have used one (if you have). Just to be clear, we are ...
Запуск __call () в PHP, даже если метод существует
В документации PHP говорится следующее о магическом методе __call(). : __call () запускается при вызове недоступных методов в контексте объекта. Есть ли способ вызвать __call(), даже если метод существует, до вызова самого метода? Или есть какой-нибудь другой крючок, который я могу р...
Магический метод PHP 5.3 __invoke
В этой теме подробно рассказывается о Когда делать / должен ли я использовать __construct (), __get (), __set () и __call () в PHP? , в котором говорится о магических методах __construct, __get и __set. Начиная с PHP 5.3 существует новый волшебный метод под названием __invoke. Метод __invoke...
Как скрыть __methods__ в Python?
Я просто подумал, как скрыть особые __.*__ методы в python *? В частности, я использую интерактивный интерпретатор Python с завершением табуляции, и я хотел бы отображать только методы, которые предоставляют мои модули ... спасибо, / myyn / * (по крайней мере, от пользователя, к...
Есть ли случай, когда len (someObj) не вызывает функцию someObj __len__?
Есть ли случай, когда len(someObj) не вызывает функцию __len__ someObj? Недавно я заменил первое на второе в (успешной) попытке ускорить код. Я хочу убедиться, что где-то нет крайнего случая, когда len(someObj) не совпадает с someObj.__len__().
Используете __call со статическими классами?
Можно ли использовать магический метод __call при статическом вызове функций?