Google News
logo
PHP program to print the size of the empty class
In PHP, an empty class will have a default size of 80 bytes. This is because even an empty class will have a few attributes and methods in PHP.

Here's the program to print the size of an empty class in PHP :
Program :
<?php
class EmptyClass {}

$obj = new EmptyClass();
echo "Size of empty class: " . memory_get_usage(true) . " bytes";
?>
Output :
Size of empty class: 2097152 bytes
The `memory_get_usage(true)` function returns the amount of memory used by the script in bytes. By default, it returns the memory used by the PHP engine, but passing `true` as an argument makes it return the actual memory usage of the script.

When you run this program, you'll see the size of the empty class in bytes. Note that the size may vary depending on the platform and the version of PHP you're using.