Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the php function 'overload' do?

Tags:

methods

php

According to the PHP documentation:

The overload() function will enable property and method call overloading for a class identified by class_name.

http://www.php.net/manual/en/function.overload.php

But what does that mean exactly? Does it mean I can do proper overloading on that class (like Java's overloading)?

like image 633
Anthony Bishopric Avatar asked May 27 '12 06:05

Anthony Bishopric


People also ask

What is Overloading in PHP?

Overloading ¶ Overloading in PHP provides means to dynamically create properties and methods. These dynamic entities are processed via magic methods one can establish in a class for various action types.

What happens when you overload a function?

Using the function overloading concept, we can develop more than one function with the same name, but the arguments passed should be of different types. Function overloading executes the program faster. Function overloading is used for code reusability and to save memory.

Does PHP allow function overloading?

PHP does not support method overloading. In case you've never heard of method overloading, it means that the language can pick a method based on which parameters you're using to call it. This is possible in many other programming languages like Java, C++.

Why do we overload a function?

The main advantage of function overloading is that it improves code readability and allows code reusability. The use of function overloading is to save memory space, consistency, and readability. It speeds up the execution of the program. Code maintenance also becomes easy.


1 Answers

It basically enables the magic accessor methods such as __get(), __set(), etc.

Since PHP5 this is no longer necessary and enabled by default. In fact, you can't switch it off ;-)

like image 55
Ja͢ck Avatar answered Sep 21 '22 14:09

Ja͢ck