Q:

PHP program to print the size of the empty class

belongs to collection: PHP Classes & Objects Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Classes & Objects Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
PHP program to create a class with setter and gett... >>
<< PHP program to initialize data members without usi...