PHP program to print the size of the empty class

Here, we are going to learn how to print the size of the empty class in PHP?
Submitted by Nidhi, on November 10, 2020 [Last updated : March 13, 2023]

PHP - Size of an Empty Class

Here, we will define a class Student and then print the size of the object of the empty class using the sizeof() function.

PHP code to print the size of the empty class

The source code to print the size of the empty class is given below. The given program is compiled and executed successfully.

<?php
//PHP program to print the size of the empty class.
class Student
{
}

$S = new Student();
echo "Size of object: " . sizeof($S);
?>

Output

Size of object: 1

Explanation

In the above program, we created an empty class Student. After that we created the object "$S" of the Student class and then print the size of the object, it will print 1, because the size of an empty class always one to differentiate the address space for objects.

PHP Class & Object Programs »



Related Programs




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.