---
title: "Most Popular PHP Magic Methods"
url: https://www.exakat.io/most-popular-php-magic-methods/
date: 2019-09-27
modified: 2025-02-17
author: "dams"
description: "Most Popular PHP Magic Methods PHP features the concept of magic methods : methods that have a special function. They are related to other PHP features, and are automatically called..."
categories:
  - "Company"
image: https://www.exakat.io/wp-content/uploads/2019/09/magic.320.jpg
word_count: 223
---

# Most Popular PHP Magic Methods

[![](https://www.exakat.io/wp-content/uploads/2019/09/magic.320.jpg)](https://www.exakat.io/wp-content/uploads/2019/09/magic.320.jpg)

# Most Popular PHP Magic Methods

PHP features the concept of magic methods : methods that have a special function. They are related to other PHP features, and are automatically called on an object, when available. 

For example, the __toString() method is called whenever an object is converted to a string : this may be with a type cast, a call to echo or print, or a concatenation. When such method is not available, a default behavior is used.

There are no less than 15 magic methods in PHP. : 

- [__construct](http://www.php.net/__construct)

- [__destruct](http://www.php.net/__destruct)

- [__call](http://www.php.net/__call)

- [__callStatic](http://www.php.net/__callStatic)

- [__get](http://www.php.net/__get)

- [__set](http://www.php.net/__set)

- [__isset](http://www.php.net/__isset)

- [__unset](http://www.php.net/__unset)

- [__sleep](http://www.php.net/__sleep)

- [__wakeup](http://www.php.net/__wakeup)

- [__toString](http://www.php.net/__toString)

- [__invoke](http://www.php.net/__invoke)

- [__set_state](http://www.php.net/__set_state)

- [__clone](http://www.php.net/__clone)

- [__debugInfo](http://www.php.net/__debugInfo)

## PHP Magic Methods

We polled a corpus of 1705 Open Source applications, to check their respective usage of magic methods. Anytime a project defines, at least once, a magic method, it is counted. 

![Most popular PHP magic methods](https://178.62.231.40/wp-content/uploads/2019/09/magic_method.stats_-1024x594.png)PHP most popular magic methods

## A few notes

- All magic methods are quite popular. This is a widely used concept.

- The most common magic method is `__construct()`, by far. It is almost compulsory for a class, yet it is surprisingly low in usage, at 63%.

- `__toString()` is quite popular

- `__debugInfo()` was introduced in PHP 5.6

- `__get()` is more popular than `__set();`__sleep()`is more popular than`__wakeup()`. 

- `__destruct()` is only used half the time of `__construct()`. 

- `__serialize()` and `__unserialize()` are only available in PHP 7.4. Either those projects are already compatible, or they will have to refactor some code.