tags:

views:

23

answers:

1

Hi
I'm new to OOPS, Can you guys suggest me which way is better to call a function of a class in PHP and why? the scenario is as follows.

class A
{
     function B (){}
}

Which method will take less resource to call the function B

1. A::B();

or

2. $obj = new A();  
   $obj->B();
A: 

Well, the second way creates an unnecessary temporary object, so the first one is faster. But if you have an object created anyway, it wouldn't matter.

Gleno