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

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

Program/Source Code:

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.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.