Re: OOP Static Functions vs. Objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Edward Vermillion wrote:

On Apr 30, 2006, at 10:10 AM, Jochem Maas wrote:

Edward Vermillion wrote:

I'm still trying to get my head around all the OOP stuff and was wondering if there is any basic difference between calling a static function as opposed to creating an object, in situations where both methods will do the same thing for you. Is there any overhead to creating an object from a class that might impact time/memory consumption(efficiency), or does PHP treat these two methods the same? I'm currently working with PHP4 but am also curious as to how it works in PHP5.


creating an object is a lot of overhead,


That's what I was thinking, but wasn't sure. I'm looking for a 'best practice' really, I've just 'discovered' the static keyword in PHP4, and have a very superficial knowledge of it in PHP5.

in php5 you can mark class variables and function as static ontop of the
ability to declare variables inside functions as static (as you can in php4)

I remember 'discovering' the static keyword - what an eye opener is was :-)


don't even try to compare objects in php4 and php5 on anything other than
a superficial level - php5 has so much more OO functionality that it's
jsut not funny. :-P
for instance all those '&'s you are using - php5 doesn't
need it (throws E_STRICT errors at you actually if you use them)  because
objects are always references (unless you specifically clone them)

I recommend going to php5 if your currently developing new php OO code, this might not be possible due to production env. restriction but it doesn't stop
you installing a copy locally and getting your hands dirty :-)

have fun.


That's what I'm doing now. I've got 5.1.2(?) loaded up on my main dev

5.1.2 is a good release to start with (for one it up2date ;-) because
you miss out on all the 5beta3 -> 5.0.1 -> 5.0.5 -> 5.1	migration hoops
that some of us had to jump through - I feel that at this stage the functionality
and behaviour of the engine is really settling down nicely (php6 will
bring it's own set of migration issues though - not much you can do about it -
software evolves right :-P)

server and am getting my feet wet with the OOP stuff. The only 'problem' I'm facing at the moment is that a lot of the work I do is for clients on shared hosts, and you know what that means as far as being able to do a total migration to PHP5.

I have the luxury of running my own server(s) so I can do what I want
(obviously client code runs on my servers :-) most of the time, sometimes
I have to use php4 (almost inescapable given that just about all shared-hosting
is still php4) -  writing 'proper' php5 code is impossible if you have to be
able to run it on php4 machines - so that is indeed a big drawback.


Right now I'm looking at getting the PHP4 code I have into a state  that

refactoring (cleaning up ;-) is always a good idea - if the code is neat and
well designed it won't be too hard to move it to php5-only when you are able ...
it does mean you can't use any

resembles as much as possible what it will look like in PHP5, just to keep the different versions I'm going to end up with as close as possible.

CVS or subversion (and 3 weeks intensive study of what branches are) might
be of help to you - not for the faint-hearted though!

Thanks!
Ed

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux