magic-function

When do/should I use __construct(), __get(), __set(), and __call() in PHP?

A similar question discusses __construct, but I left it in my title for people searching who find this one. Apparently, __get and __set take a parameter that is the variable being gotten or set. However, you have to know the variable name (eg, know that the age of the person is $age instead of $myAge). So I don't see the point if you HA...

In IPython how do I create aliases for %magics?

Let's say I want to create the alias %xed for %edit -x. How would I do it? ...

Magic functions and inheritance

I would like to know if it's possible to create a magic object that extends another magic object, (with PHP). ...

What's the magic function for empty() in PHP?

It should not be __isset,because isset() is not the same thing as empty() ...

Difference between normal and magic setters and getters

I am using a magic getter/setter class for my session variables, but I don't see any difference between normal setters and getters. The code: class session { public function __set($name, $value) { $_SESSION[$name] = $value; } public function __unset($name) { unset($_SESSION[$name]); } publi...

Mercurial/Python - What Does The Underscore Function Do?

In Mercurial, many of the extensions wrap their help/syntax string in a call to an underscore function, like so: _('[OPTION] [QUEUE]') This confuses me, because it does not seem necessary (the Writing Extensions instructions don't mention it) and there doesn't seem to be a _ defined in the class, so I'm wondering if this is some spec...

Magic functions __call() for functions?

The magic function __call() in php are used in classes. Are there any similar magic function but for functions instead? Like __autoload() is for functions. For example something like this function __call($name, $arguments) { echo "Function $name says {$arguments[0]} "; } random_func("hello"); ...