OOP | When to use Static Methods @ Book: PHP in Action

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

No, php is not an interpreted language in a strict sense. Php engine first compiles entire file into bytecodes, and than executes the bytecode stream. That is, there is a strict separation between compile- and run time in php, just like in C.
Behzad
Forum Commoner
Posts: 28
Joined: Mon Jul 09, 2007 3:24 pm
Location: Tehran, Iran
Contact:

Post by Behzad »

I never knew this.
So why we can't publish the byte-codes like Java and run them under a PVM (PHP Virtual Machine)?
Isn't this faster? (I'm asking because you've implemented pihipi).
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

APC is an existing project that takes advantage of PHP's bytecoded nature. There are already at least two projects under-way to write additional PHP virtual machines both of them new at least one of them sponsored by IBM.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Behzad wrote:What's wrong with $product = new Product($productCode) ?
Nothing. My general response to your question is that you should always an instantiated object until you find a problem where you simply cannot solve it without using a static.
stereofrog wrote:The problem is, what should "new User($id)" return when no such user exists?
Either a User record that contains no data (and is in a error state) or and exception.
(#10850)
Behzad
Forum Commoner
Posts: 28
Joined: Mon Jul 09, 2007 3:24 pm
Location: Tehran, Iran
Contact:

Post by Behzad »

Well, it sounds everyone has an idea and I'm a little confused.
I'm going see some sample codes online. Thanks every one.
However, I still rather to use static methods which returns an instance of the class :D
Post Reply