The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Of course polymorphism has everything to do with OOP. I never said otherwise. It was you who said that overloading had everything to do wich OOP, which is incorrect. You mix up the various definitions of polymorphism in the link you posted (overloading is a kind of polymorphism according to that definition, but that kind of polymorphism had nothing to do with OOP), and I only pointed that out.

Originally Posted by mr tinkles

What do you think OOP means?

You're asking me? Want my resume? And while we're at it, may I see yours?

The person who tells others that they don't know enough about some subject, is surprisingly often the one who knows the least about that subject...

Originally Posted by mr tinkles

See the above definition of polymorphism, means having "having multiple forms", NOT multiple names. The example has little or nothing to do with polymorphism.

The example has everything to do with polymorphism. A Ferrari (in my example) is another 'form' of a car; not another name.

Originally Posted by mr tinkles

As defined, may not work reliably. True, all Ferrari's are Car's, but not all Car's are Ferrari's. If drive() method written for Car, and doesn't take potential for Ferrari object, then implicit cast will occur and you will lose Ferrari functionality in drive() method and get just Car (will need to cast back to Ferrari object).

Correct. And this is precisely the problem with your so-called overloading example 'method (Object o1, Object o2, ...N)'. Again, I only pointed that out using this example. The only one you're arguing with here is yourself.

Originally Posted by mr tinkles

Not a good OO example. Ferrari different than Car, though is car. Do you take your Ferrari to a Car mechanic?

Why not? A ferrari is a 'form' of a car (in your speak), so it supports everything a normal car does. So if it doesn't work because of a simple 'car' problem, any Car mechanic can fix it. That's the whole point of polymorphism. The Ferrari -> Car (Or Student -> Person) example is a famous (or infamous) one. And now you're saying it's a bad example? That's a good one!

Originally Posted by mr tinkles

That's a good thing? And when an object that doesn't have drive() is passed, what now? I can call unknown methods on unknown objects, how it that good?

It's not good OR bad. It's different. It allows you to do either very stupid things, or very great things, depending on your knowledge and experience. And it's totally different from Java (or C++).

You're asking me? Want my resume? And while we're at it, may I see yours?

Yes, I'm asking you...

You have a definition of OOP on your resume?

I have no desire to see your resume, but I'll send you mine, pm me or whatever and I'll email. Though I'm not sure my resume defines the OO implementations to a high degree.

My definition of OO is this:

Programming Language needs to support all of these:

Inheritance
Polymorphism
Encapsulation (data hiding, though I dislike that term)

Onward.

The example has everything to do with polymorphism. A Ferrari (in my example) is another 'form' of a car; not another name.

"having multiple forms" BEING named the same, sorry if that wasn't clear. This is the definition of polymorphism, not my slant, or what I think it is...

Both defintion links provided, support this, same name different functionality.

In your example, Ferrari is a new class inherited from Car, they not named same. Guess I can easily say you Ferrari/Car example not good polymorphic example, but inheritance and polymorphism are related, not correlated.

The person who tells others that they don't know enough about some subject, is surprisingly often the one who knows the least about that subject...

Psychology, interesting.

So what do you call a person that actually does know the subject?

Mr Tinkles, i think you should re-asses your 'arguments' and who's skills you are questioning.
If u write badly designed code, you will get a bad result.

Ok, let's question your skills responsibility.

GIGO. That's, garbage in, garbage out.

Do you need to have good programming practices enforced upon you, or can you take responsibility?

what do you think?

I'll take "sponsitility". Enforcing good programming practices, because the programming language doesn't, is the same as a developer saying:

"If the user makes a mistake, the program should crash"

What's worse, is, if programming language, allows this to happen, when I enforce good programming practices!

"PHP does not support function overloading, nor is it possible to undefine or redefine previously-declared functions"

That blows out Polymorphism, also!

I would

Resumes and degrees aside.... (everyone (& I have neither )

Mr Tinkles you said that PHP does not have the 3 basic requirements of OOP and is therefore not really OOP , I think only the polymorphism issue was at task and I think thats been thouroughly covered.

So again, if you are saying that lack of private,protected vars etc & lack of abstract classes etc makes OOP a little more work in PHP then no one will argue with you.

You are suggesting that PHP OOP is not capable of certain things because of these 'shortcomings' which I think you would need to show us if your argument is to hold any water, the flawed example you showed earlier was exactly that designed only to show how its possible to stuff-up .

If you saying that its impossible to write bad code in Java then that would be another point for you... not holding my breath though.

not quite with you Mr T , what shopping cart ? , you mean you grabbed an existing shopping cart class and tried to extend it and it did not work ?

Then write your own class , its hardly PHP's fault if the class was not up to scratch, if you can do it better than be a nice PHP head , repair it and notify the creators of your improvements.

Currently most available classes are those that peeps have created for themselves and then made available to others if they wish to use them, often they will reflect the needs of the creators rather than the masses.

A couple of useful classes for the real world on & offline are snoopy and r&os PDF neither are perhaps brilliant examples of PHP OOP but both very functional and both very useful, I often use snoopy for simple web-fetching and parsing and extend r&os pdf for making simple PDF templates/merges.

Then write your own class , its hardly PHP's fault if the class was not up to scratch, if you can do it better than be a nice PHP head , repair it and notify the creators of your improvements.

Ditto.

Mr Tinkles:
I'm not sure why you feel paralyzed that an existing class has a method named the same that you would like to name. Just replace it with your "discount" method. Talk about making a mountain out of a molehill! If this is what you've been arguing about the whole time, I think you need to re-evaluate your priorities.

Mr Tinkles:
I'm not sure why you feel paralyzed that an existing class has a method named the same that you would like to name. Just replace it with your "discount" method. Talk about making a mountain out of a molehill! If this is what you've been arguing about the whole time, I think you need to re-evaluate your priorities.

I have to give mr tinkles credit, you surely are stubborn. Although I have to question why you would declare an ambiguous function to an object. Before you start slandering that with "Private" and "public" were getting there with PHP5. If PHP is not up to your standards, then why are you coding in it or better yet, why are you coding in a loosely typed language?

Most people will agree that it's learning curve is easier to get round than something like java, but the real reason is it's far more productive in my eye's; quick. Anyway, getting back to your question in hand...

You are obviously losing the plot in many cases, yes poor coding does make any language fail in many apsects, but if you handled something like that, you would check prior for the objects existance "class_exists" and "method_exists". Hopefully with the "new namespaces" in php5 we will have a better solution to this, however you have to stick to the lanuages constructs or all else will fail.

Sure, define "the real world". Or show how PHPs OO is helpful in "the real world"? prove me wrong right quick.

Are you still trying to argue that in the real world, no one is using PHP's OOP? I think it's time you had a look around in that case.

I think the reason why you got no feedback here is not because no one has any examples but because your question is not far from "show me a website that works and uses PHP"...

I could spend the next month finding you links to real sites that I know are using PHP's OOP. For starters check out the eZ publish class library then check out 200 + sites listed as using eZ publish. Of course none of them actually exist because PHP's OO support is un real, my name isn't Harry and I exist only as a figment of your imagination...

I think that everyone who has posted on the Advanced PHP Programming section of sitepoint has used OOP as a tool to some degree in at least some of their apps. I use it all the time, and yes, all of my apps work. They all work far better than scripts just like them that are using PP, and their are far easier to maintain, upgrade, and extend. But, each man to his own; that's the beauty of PHP. You can do PP, or OOP or even OOPP (Object Oriented Procedural Programming (In Theory)), and no one could stop you. If it works, great, if it doesn't, that's fine too.

Did just do the 'poor man's extend' to the cart class. Meaning, just 'update' existing class...

Although I have to question why you would declare an ambiguous function to an object. Before you start slandering that with "Private" and "public" were getting there with PHP5. If PHP is not up to your standards, then why are you coding in it or better yet, why are you coding in a loosely typed language?

I actually wouldn' declare stuff ambiguosly (knowingly), just an example (as explained), that shows what is possible. Kinda funky example, that leads to some interesting possibilities...

PHP actually does meet some of my standards, and I code with it because, I can? But what difference does that make? rhetorical..

...You are obviously losing the plot in many cases, yes poor coding does make any language fail in many apsects, but if you handled something like that, ...

Maybe just being stubborn, but I'm still on 'plot'.

btw, a little OO better than NO OO.

Plot, for me, is "How good is PHP OO?" or better "what benefit is PHP OO?"

A great thing about OO, should be the ability to reuse code/objects. If I have to write more code to handle doing this, kind of defeats purpose. Kind of like how PHP supports 'overloading'. Seems more trouble than worth. Not gaining anything, just more coding for issues...

Andrew-J2000, as you allude to the private/public, instance/class scoping of variables, you may be leaving out the ability to override. This isn't an issue with strong/loose typing,btw. In the above example, the inability of PHP to recognize the scope of each objects variables/members, will not be solved by public/private keywords.

if:

PRIVATE var $count;

in each class would hide scope, perhaps, but:

PUBLIC var $count;

will cause even more problems/issues as PHP needs to be able to encapsulate objects properly...

Lastly, PHP OO can be described as this:

Simple object concept/creation
Strict inheritance over many levels. Meaning, highest level scope, always rules, may not be what one wants. Proceed at own risk. This is the same as strict overriding. This also means encapsulation is not guaranteed, nor enforced. Proceed at own risk
No overloading.

Is PHP OO, sure, as it has some OO capabilities. Is PHP good at OO, er, ah, no. Unless you prescribe to the:

segway is a car because it has wheels, own power source and transposts people...

"It would be nice to see an actual class that could be part of an actual website or PHP application"

your question is not far from "show me a website that works and uses PHP"...

That's not a question, statement. Statement much closer to the question:

Is PHP OO, sure, as it has some OO capabilities. Is PHP good at OO, er, ah, no.

Are you just going on for the sake of having an argument. If you are a good software engineer you can use PHP to write good OOP. The language (in PHP4) might directly support ALL OOP techniques, but you can still do it.

You might have to write a few more lines to do something OOP related than you would in java, but then you have to write a whole lot more typing code in java. Once you have written a re-usable class you don't have to rewrite again (if you designed it properly), so the excuse:

Originally Posted by mr tinkles

If I have to write more code to handle doing this, kind of defeats purpose. Kind of like how PHP supports 'overloading'. Seems more trouble than worth. Not gaining anything, just more coding for issues...

just isn't an excuse! Learn to engineer your software. If u need to have certain language specfics before you think you can write good OOP, then why not start helping with the PHP5 development?

Maybe you should wonder how it is that you're unable to write a useful class, or even find one on the Internet. Hint: don't put the blame on others (like the PHP developers), and take a closer look at yourself.

If you are a good software engineer you can use PHP to write good OOP. The language (in PHP4) might directly support ALL OOP techniques, but you can still do it.

As a software developer, I can use FORTRAN (or C, or basic) to write good OO.

But that is not the 'plot'. Writing good OO and the OO abilities of a given language, are two different things.

If u need to have certain language specfics before you think you can write good OOP, then why not start helping with the PHP5 development?

How is that accomplished? I sent an email through www.php.net and never got reply. Though I'll gladly offer...

Maybe you should wonder how it is that you're unable to write a useful class, or even find one on the Internet. Hint: don't put the blame on others (like the PHP developers), and take a closer look at yourself.

I will put the blame where it squarely lies. The PHP implementation of OO, or objects, rests in PHP, not the coder. If PHP allows bad things, question that, not:

why coder trying to do bad things.
---
As a software developer, I WILL NOT ACCEPT:

"If the user does something wrong/stupid/funny, then when software fails, IT IS THE USERS FAULT."

It is the fault of the software/developer to allow this to happen, NOT the user.

I will put the blame where it squarely lies. The PHP implementation of OO, or objects, rests in PHP, not the coder. If PHP allows bad things, question that, not:

why coder trying to do bad things.
---
As a software developer, I WILL NOT ACCEPT:

"If the user does something wrong/stupid/funny, then when software fails, IT IS THE USERS FAULT."

It is the fault of the software/developer to allow this to happen, NOT the user.

Soooo, if I read this correctly, you think it should be the job of the LANGUAGE to hold your hand, point out your mistakes, show you the correct coding structures, and generally do all of the work for you?

You may as well say "If I write broken code becuase I don't know how to program in PHP properly then its PHP's fault when it doesn't work." Either way, you're just seeking ways to absolve your own ineptitude.

How annoying

This thread must have lots of links to it because it comes up quite a lot when googling for REAL information about OO in PHP4, instead you get Mr. Tiddles making hard and fast rules about how programming languages should work. Sadly it is typical of a attitude amongst a minority of coders, put a sock in it if you can't come up with anything practical.