Reputation: 17589
So what really happens when someone say 'new' in PHP
I believe in C/Java, when new is called, memory is allocated for each instance variables that are needed for an object? (correct me if i am wrong)
Is this the same with PHP?
Upvotes: 5
Views: 4557
Reputation: 97825
When you use $var = new Class
$var
is associated with this created zval container.1 Definition of what's a zval container.
Upvotes: 6
Reputation: 382696
The easiest way would be to check it for yourself using memory_get_usage()
echo memory_get_usage();
$obj1 = new obj1;
$obj2 = new obj2;
$obj3 = new obj3;
echo memory_get_usage();
Same is the case with PHP.
Upvotes: 2
Reputation: 14365
When you say new
in PHP, PHP assumes you'd like to call a new Class
: PHP Classes Basics.
Upvotes: 0