Web Hosting Talk







View Full Version : Web OOP Language


livepvp
12-10-2007, 07:30 PM
I have been a PHP advocate for many years, however recently I have begun to question the usefulness of PHP in my deployment. The OOP support in PHP5 seems to be somewhat lacking compared to many other languages and as I move more into using OOP in my day-to-day coding I have begun to question wehther or not there is a better Web OOP language.

Any suggestions, comments, or arguments are welcome as I am looking for the best solution!

Xeentech
12-10-2007, 07:44 PM
PHPs "OOP"-ness is a bit pants some times, for example.. $obj->something()->other(); will work, yet $obj->something($arg)->other(); will bail.. This came up recently, can't remeber where, but it was annoying!

The solution was SO ugly.
$temp = $obj->something($arg);
$temp->other();

I mean what the hell.. it's 2007, nearly '08.. c'mon!

stdunbar
12-10-2007, 11:59 PM
What is it you're looking to do? If it is general web and/or application development Java has a pretty wide variety of capabilities. Like PHP it requires an VM environment outside of any O/S you run.

While the PHP syntax that Xeentech is a bit C++'ish, the Java syntax would be something like obj.something(arg).other();

Now on this forum suggesting that PHP is somehow inferior is bordering on computing blasphemy. Just ask those folks who suggest so why zero of the 60 SPEC web 2005 published results (http://www.spec.org/web2005/results/web2005.html) use PHP when the test allows either PHP or Java use.

Just my $0.02 worth.

jayantk
12-11-2007, 11:02 AM
there is nothing called a perfect world and hence you cannot have a perfect language.. each language has pros and cons and you need to decide which one fits best depending upon the problem and the requirements :)

jstanden
12-11-2007, 06:04 PM
Better is relative to whatever you're trying to accomplish. If your opinion waxes and wanes with fads you're never going to be happy. ;)

PHP has plenty of faults, but it also has an incredibly wide installed base as a trade-off (opposed to, say, Ruby).

I love Java myself (Tapestry/Hibernate/Jasper), but we can never seem to get the same enthusiasm out of our customers for it as we can with PHP.

I've done some pretty elaborate things with PHP5, for over ten thousand installed sites, and honestly the OOP faults in PHP don't cause major problems. Namespaces become a pain, but occasionally having to break up your $ref->ref()->ref()->ref() calls isn't worth a mutiny.

the--dud
12-13-2007, 07:55 AM
To be perfectly honest with you. I still view PHP as a 'introduction' language. I programmed with PHP for some years. But when I got more comfortable in different languages, I found myself just logically drawn towards creating applications for web instead of scripts. It's more powerful, flexible, and often scales better.
Hence I use Java for any web programming now.

Even though I love OOP with a passion, it was ironically enough the introduction of OOP that threw me off using PHP.
I feel personally PHP5 was a move in the wrong direction.
OOP is without much better suited for applications rather than scripts. By applications I mean obviously a program running infinite loop, and negotiation with incoming requests(through apache/etc, or as standalone).
Stateless PHP scripts on the other hand, I've never properly seen the need for OOP...

Just my 2 cents but...

Steve_Arm
12-13-2007, 10:36 AM
Provide example where the language was not sufficient to meet your needs.

I have been a PHP advocate for many years, however recently I have begun to question the usefulness of PHP in my deployment. The OOP support in PHP5 seems to be somewhat lacking compared to many other languages and as I move more into using OOP in my day-to-day coding I have begun to question wehther or not there is a better Web OOP language.

Any suggestions, comments, or arguments are welcome as I am looking for the best solution!

jstanden
12-13-2007, 03:17 PM
Stateless PHP scripts on the other hand, I've never properly seen the need for OOP...

That's insanity.

Renard Fin
12-13-2007, 03:44 PM
PHPs "OOP"-ness is a bit pants some times, for example.. $obj->something()->other(); will work, yet $obj->something($arg)->other(); will bail.. This came up recently, can't remeber where, but it was annoying!

The solution was SO ugly.
$temp = $obj->something($arg);
$temp->other();

I mean what the hell.. it's 2007, nearly '08.. c'mon!

Not sure, but ... would this work ?


Class X
{

public function __call($func, $arg)
{
if (ereg('(get_)(.+)', $func)) {
$obj = $this->method($fun);
return $obj;
}
}

public function method($arg)
{
$x = new StdClass();
$x->$$arg = $arg;
return $x;
}
}

$x = new X;

$x->get_func()->func;


or something like that ? I haven't tested this out, but I think it could work.

TonyB
12-13-2007, 04:08 PM
Stateless PHP scripts on the other hand, I've never properly seen the need for OOP...

Just my 2 cents but...



That's insanity.

I totally agree that is insanity. I make use of inheritance, abstract classes, static functions and vars in a class.


But lets take a look at something as simple as Zend_db http://framework.zend.com/manual/en/zend.db.html .

If you use it's factory setup and your queries are the same across all databases you could very well support pgsql, mysql, oracle ect. all with a simple change in a config file.

I'm sure if you wanted you could make a super ugly solution like that procedurally.

masfenix
12-16-2007, 02:03 AM
If you wanna go windows then theres .net 2.0. SOme hosts have already switched to .net 3.5 with support for LINQ and silverlight.

I switched from php to vb.net, and havnt looked back since.

plumsauce
12-16-2007, 06:16 AM
Search for "micronovae"

Very obsure, but a great concept.

It creates websites using c++ based on the classic asp object model.

phporaclehosting
12-17-2007, 09:30 AM
PHP 5 is a reasonable OOP language, if you need more enterprise then go java, i would shy away from .net route, as you don't get all the enterprise goodies, may be this is flame ware bait

BSD4
12-17-2007, 11:24 PM
PHP is certainly a language that doesn't hurt to know. I've worked with a few PHP programmers before and it's amazing - everything can be done with it. A few of my friends thought they wanted .NET programmers for a job, but I talked them out of it. All in all, learn PHP :D

torqhost
12-18-2007, 01:56 AM
I have also been a PHP developer for years now and I too feel your pain. What I am generally dissatisfied is with it's slow evolution. Now I am not speaking about libraries and such, but language features such as more advanced OOP.
PHP is great if you don't care about MVC / code reusability / all valid OOP principles and such. Sure, there are MVC frameworks, I tried CakePHP and Symfony, but compare them to ROR or Django and you will see how weak they are. Cake was chosen for our last project and it has been just killing me with some of it's problems (like hasMany relationship support absolutely not working an executing too many queries).

Not sure about all others, but I myself am just fed up with PHP, it could be also because I have been working with it for so much time and have not seen any improvement from the language, not sure.
What I know for sure though, is that if you don't know / care what MVC is, then you probably should continue using PHP, as in this sense I cannot argue, that it is the best thing our there (simplicity wise, at lease to my knowledge)...

Renard Fin
12-18-2007, 03:00 AM
There is something that doesn't help here torqhost.

I would say that as january about 50% of the hosts were only serving php 4, and now I would say 90% of them are hybrid, serving php 4 by default, and using php 5.1 as the latest PHP version.

This is where the bottleneck is as there are a lot of hosts who are reluctant to upgrade quickly. Namespaces are in the next public release ( 5.3 ).

ans_steve
12-18-2007, 03:58 AM
I use Zend_table, Zend_controllers, together with Smarty. I really think this is a great combination.

Ryan F
12-21-2007, 03:01 AM
Provide example where the language was not sufficient to meet your needs.

Anyone who's ever written a large application in PHP can give you reams of examples "where the language was not sufficent to meet [their] needs."

Steve_Arm
12-21-2007, 04:02 AM
OK I'll just ask myself... Never.

Anyone who's ever written a large application in PHP can give you reams of examples "where the language was not sufficent to meet [their] needs."

TonyB
12-21-2007, 11:26 AM
Anyone who's ever written a large application in PHP can give you reams of examples "where the language was not sufficent to meet [their] needs."

Well one example is function overloading (I believe that's the name for it)

So you have a class and then you have 5 add functions with different parameters

add($var)
add()
add($var,$var)
add($var,$var,$var)

It'll never be as powerful as some other languages due to just no types in play as well. You can set default values on each var to get around then do some if statements to get around this. But I prefer to be able to do this

dollar
12-21-2007, 11:44 AM
As you probably know TonyB, you can overload functions in PHP... just not in a normal way.

i.e. (borrowed from: http://us2.php.net/manual/en/language.oop5.overloading.php )


function whatever() {
$args = func_get_args();

// public boolean whatever(boolean arg1) in Java
if (is_bool($args[0])) {
// whatever(true);
return $args[0];

// public int whatever(int arg1, boolean arg2) in Java
} elseif(is_int($args[0]) && is_bool($args[1])) {
// whatever(1, false)
return $args[0];

} else {
// public void whatever() in Java
echo 'Usage: whatever([int], boolean)';
}
}

Steve_Arm
12-21-2007, 02:21 PM
The truth is that you don't really need function overloading in PHP
because it's not a type safe language.

TonyB
12-21-2007, 06:20 PM
As you probably know TonyB, you can overload functions in PHP... just not in a normal way.

i.e. (borrowed from: http://us2.php.net/manual/en/language.oop5.overloading.php )


function whatever() {
$args = func_get_args();

// public boolean whatever(boolean arg1) in Java
if (is_bool($args[0])) {
// whatever(true);
return $args[0];

// public int whatever(int arg1, boolean arg2) in Java
} elseif(is_int($args[0]) && is_bool($args[1])) {
// whatever(1, false)
return $args[0];

} else {
// public void whatever() in Java
echo 'Usage: whatever([int], boolean)';
}
}


I had seen solutions like this before. But as I said this is no where near a clean solution.



The truth is that you don't really need function overloading in PHP
because it's not a type safe language.

It may not be type safe, but when you're building php applications you could find a use for functions with no arguments and one with. I recently built something that would have been able to use this. Instead I had to create logic to handle if any parameters came in.


I also had an instance where I was retrieving the same results. However the data coming in to retrieve these results may vary.


So one instance it comes in with

getSomething();
getSomething($var);
getSometing($var,$var);

This all in a class

getSomething would work if the constructor before the required values. The others one took an int the other took two strings.

Each instance returns same dataset however the way it retrieves them changes.


Oh well just a rant

The ability to specify actual types in PHP fully and function overloading would be awesome.