in my general practice of laziness, i decided to scroll through my bookmarks for the php.net site instead of typing it in the address bar, which to my surprise, i don't have in there! but, i saw this bookmark titled "PHP Anthology...", so i thought... hmmm... what is this? i don't recall putting it there...

so, i followed the bookmark to this site. after looking at the content, i think i know why i added the bookmark-- it is a solicitation for books called the PHP Anthology: Object Oriented PHP Solutions. up until i began my quest to study and learn PHP just a few short months ago, i was tooling around (first w/ coldFusion as my personal project, and then...) w/ ASP.NET because that's what my workplace wants me to use to build some simple stuff to integrate into our enterprise software-- workflow management environment in which we're required to communicate our tasks, progress status, etc, blah, blah. i likely bookmarked the link above because the way i understand it, ASP.NET is "object oriented" programming, so i wanted to see how the concept applied to php (although i never bought the books yet). i'm not really sure what the term really means, but i have my ideas about it. i understand it's a rather challenging concept to get the hang of it (at least of you've been an ASP programmer-- as in, it is NOT the same, and therefore is the source of frustration for many of yesterday's ASP developers).

anyway, not to get too far off on a tangent, i'm curious, have any of you investigated that book at my link above, and/or, have you any experience w/ PHP: Object Oriented programming? If so, i'd really like to hear a bit about it. i am still very much in the infant stages of my PHP knowledge and understanding, but i can't help but be curious as to what this Object Oriented PHP is all about. or is this guy just trying to make a buck off of people who don't have a desire to truly learn PHP? it is my desire to learn as much as i can, and have the most thorough knowledge as possible before my brain explodes. (i was never a math wiz, but logic, i can handle. so far, so good w/ PHP-- i just wish i had some live people to discuss it with, and some good exercises to test my understanding, and exercise application of logic and functions to the solution of problems presented.)

When i first heard our systems guy at work explain ASP.NET, and object oriented programming to me, i thought it sounded a bit like some things i had encountered in coldFusion-- the CFC's-- coldFusion components. i never got far enough into ColdFusion to have a good enough understanding to say truly whether it is or is not Object Oriented, obviously in part because i don't really even know what the term means in the first place! also, it's very easy to let DreamWeaver write to code for you, so you can do stuff w/out really knowing what you're doing-- if that makes any sense. needless to say, i am no ColdFusion developer by any means-- i simply played a bit w/ it as a seamless integration w/ DW, which i venture to guess is a dirty word, if not totally disregarded here in this forum. 😉

sorry, i don't mean to sound like a flake-- i'm just curious to hear what some of you much more experienced programmers have to say about the concept of Object Oriented Programming in terms of PHP. sorry for my long way around getting to that question.

anyone?

    Object oriented programming in general is a vast topic. I would suggest that you read a few primers to get a feel for how it works as it's a bit too big to be explained here.

    PHP is not an pure object oriented language as Java and C# are. With PHP we can freely mix objects with procedural code, in Java and C# functions (or methods) must be contained with a class, in PHP they can exist in the global namespace, or within a class (similar with other dynamically typed languges such as Ruby in this respect). In the Java world everything is an object, in PHP the object type sits alongside integers, strings and so forth.

    PHP 4 has a limited object model, but it is sufficient in most respects. PHP 5 has an extended object model which is very similar to Java. A detailed explaination can be found at www.php.net.

    I have read some of the Anthology book, the author Harry Fuecks runs a site www.phppatterns.com - there are some useful examples on there.

      Like Shrike mentioned, OOP (Object Oriented Programing) is a huge subject, way too much to cover in my small post. That said, I can give you the basic difference between OOP and the other main type of programming - procedural. In procedural programming, common among languages like BASIC, the interpreter/compiler goes down the code, executing everything in a linear fashion, from top-to-bottom. In OOP, you can have things like functions, which are reusable pieces of code you can call over and over again. For example:

      mysql_query("SELETC * FROM blah") or die("MySQL Error: " . mysql_error());
      mysql_query("SELECT * FROM blah WHERE nonexistantcolumn = 'test'") or die("MySQL Errror: " . mysql_error());
      

      Notice how I keep using die("MySQL Error: " . mysql_error()). Since I keep repeating it over and over again, that is procedural-style. In OOP, I can replicate that above code like this:

      mysql_query("SELETC * FROM blah") or fail("An error occured while selecting from the blah table.");
      mysql_query("SELECT * FROM blah WHERE nonexistantcolumn = 'test'") or fail("An error occured with the equality test.")
      
      function fail($errormsg)
      {
           die($msg . "<br /><br />MySQL Error: " . mysql_error());
      }
      

      Noticed how I replaced the repeating code with a function, and even made it nicer with support for another message in addition the default MySQL one.

      OOP can use more than functions - the real power of OOP lies in classes, which has members (variables) and methods (functions). The members and methods exist only within in the class; that is, you can't call or reference a function or variable within a class without calling the class first. Think of classes as replicas of real life objects - for example, a "car" class would have members (variables) like "color", "size", "manufacturer", etc. - and it would have methods (functions) like "openDoor()", "startCar()", "driveTo()", etc. The class's methods interact only with the class's other methods and members, so everything is encapsulated within the class. In addition, there's support for inheritance and public/private class members but you don't need to worry about them right now.

      Now, about the books - I purchased those books a while ago and have read them many times over, and they are some of the best books I've ever bought on any programming language. They're full of real-life examples, not just fake "book" examples which have no purpose in the real world. They're an excellent buy; I'd reccomend them whole-heartedly.

      Hope I helped you to understand a bit more about OOP!

        Just to clarify something - your MySQL example is procedural. A procedure can be defined as a set of instructions which are executed linearly, in other words, a PHP function.

          However, functions are still considered part of OOP programming because the functions themselves are executed at arbitrary points in the code, when they are called, and not when they really appear along the "linear" line of code.

            By that line of reasoning GOTO statements in Basic are object oriented.

              I realize that; however, the GOTO statements in BASIC aren't really functions, per se, because they cannot return back to the line that called them. Plus it creates "spaghetti code".

              In any case, I think we can both agree that our explanations can suffice for ATS to be able understand OOP, yes?

                However, functions are still considered part of OOP programming because the functions themselves are executed at arbitrary points in the code, when they are called, and not when they really appear along the "linear" line of code.

                I think that you're thinking of modular programming, a procedural pre-cursor to object oriented programming.

                Of course, depending on one's definition of OOP, it may be possible to do OOP with functions (forsaking the OOP support), but your example doesnt demonstrate that.

                  Perhaps I am thinking of modular programming...I get confused so easily 😃

                    A bit off topic here but what programming languages are not object oriented

                      i would think there are many, but a few that come to mind are C, Basic, and VB.

                        wow. i didn't expect so much feedback on this topic, but i am grateful that you all have given your input. i'll reread this thread a few times i'm sure, to get a better grasp on the concept as described by you in sort of laymans terms... Logan, i really like the Car example.

                        funny, i'd swear i've recently learned a bit about "methods" somewhere already (maybe it was when i skimmed ASP.NET, and tried a few tutorials using the M$ Visual Web Developer) because your car analogy seemed quite familiar. however, i could be confusing it w/ something different which was similarly described as with your analogy-- maybe it was the Sams PHP book when it described arrays-- or Eric Meyer's CSS the Definitive Guide, in explanation of some style rule-- as those are really the only things i've been studying lately.

                        (man, that's really bugging me that i can't recall... it's so on the tip of my tongue!... but, in any event, i doubt it was an explanation of "methods", unless it was the ASP.NET tutorials)

                          well, if youve worked with asp (classic) using vbscript it has classes and methods. but it (along with V😎 lacks alot of other oop features making it somewhat crippled imho. a good freely available book that will teach you the principles of oop would be thinking in java, do a google for it. java's syntax is not too far from php's either so its fairly easy to understand whats going on.

                            know what? it was in fact PHP OBJECTs that i was thinking about. i forgot that the book had covered them-- having been so long since i read the "building blocks" section. i recall objects being a bit tricky at first, then they all of a sudden came to me, and i seem also to recall that i was positively intrigued by what learned (i liked 'em), and was quite interested in the concept at the time i was reading that section.

                            now that i've had some "real-world" practice, i should definitely revisit that section of my Sams "Teach Yourself PHP..." book! Or, even better yet, check out what the Manual has to say!

                              Search for Java resources relating to OOP. I recently read a chapter in a Java 2 book on OOP. It was worth paying 5 dollars for the out-dated book just to get the OOP information. Also laughing at the excitement over applets was good too, best comedy book ever! 😃

                                Hey, NetNerd85, thanks for the info! i like the info in your signature, by the way.

                                it's interesting that so many here have referenced Java as a good source of understanding OOP. why is that? i mean, obviously, there is something to be learned from the applicatoin of the OOP concept to Java programming, but why in particular is it best to start off by investigating it in terms of Java?

                                I have actually planned, as the third body of a formidible triumvirate, to learn what i can of Java in addition to PHP and CSS. This is because of my aspiration to become more involved in web development as a career, or if nothing else, as a freelance supplement to what i'm doing now. but, that is the topic for another post which i'm going to write, so it will wait for its own thread.

                                again, thank you all for entertaining my interest in OOP! i'm pleased to see that some discussion ensued.

                                  i would think there are many, but a few that come to mind are C, Basic, and VB.

                                  wtf VB and C do have OOP features they use classes and just stating basic alright some of them do not have oop but most basic compilers nowdays have oop features if not afull implementation thats like saying MSIE does'nt have HTML or CSS support because it does not fully implement them

                                    ATS16805 wrote:

                                    it's interesting that so many here have referenced Java as a good source of understanding OOP. why is that? i mean, obviously, there is something to be learned from the applicatoin of the OOP concept to Java programming, but why in particular is it best to start off by investigating it in terms of Java?

                                    There are two widely-popular OO languages around (by "widely popular" I mean ones that figure prominently in job descriptions). C++ and Java.

                                    C++ has been around since the '80s, and is excitingly baroque (its inventor has said that he doesn't expect anyone to fully understand it - it turns out that this includes himself). At least some part of this is because valid C programs had to continue to be valid as C++. But some parts of it just seem downright gratuitous.

                                    Java was developed in the early-mid '90s (and you can tell I'm not bothering to look these dates up) and is much simpler. It misses many many of the constructs that C++ has and (for the most part) is better for it. It's the current darling of many programmers and CEOs.

                                    Other OO languages are around, such as Python, Smalltalk, and Objective-C, but (unfortunately) they don't get the corporate recognition, don't get the coverage, and hence don't get the books written about them (Python is a hackers' language - a lot of its users are Perl refugees; Smalltalk is very elegant; and Objective-C lives on in Mac OSX).

                                    Whether a language is OO or not ... as I see it there are three ways you could interpret that question for any given language:

                                    1. It is possible to write in the language using an OO paradigm. This is trivial to the point of uselessness - all programming languages would qualify under this criterion.

                                    2. It provides OO constructs, though does not force you to use them or the paradigm (Javascript, C++, PHP).

                                    3. It requires an OO approach to program design (Java, Smalltalk).

                                    I guess another criterion would be whether it was designed with OO in mind (C++, Java, Python) or not (PHP, BASIC, FORTRAN).

                                      i realize it's kind of "off the subject", and i don't mean to derail the thread, and i DO intend to research this subject in great detail as soon as i am able (as i mentioned earlier my desire to learn). actually, perhaps this IS the best time to inquire...

                                      what is the difference between Java and Javascript? (of course, i don't expect a 400 level collegiate thesis, just as simple an answer as possible-- or write a novel, if you wish!)
                                      😉

                                      and, considering that difference, which should i, as an aspiring "web developer", concentrate my efforts on as a "beginner"? my guess is that i will eventually need to dabble in both. i would very much appreciate some guidance in that direction.

                                      thanks!

                                        As an aspiring web developer at your beginners phase I hink you should spend a breif time maybe one month or two dabbling in javascript. I emphasis breif because too many people gat caught up doing fancy little status bar effects and call themselves web developers but really they let the side down.

                                        After This you may wish to consider learning actionscript so get a 30-day-trial of Macromedia flash and experiment with it for 28 days then you can decide if yu want it but again you will not dilly dally for too long or you may become too obsessed with bandwidth sucking flash

                                        Finally then you can get onto HTML and CSS just skim read the whole subject build a couple of W3C compliant pages if you like and then learn Java Trust Me on this one it will take some time and for anyone without previous OOP experience it can be an absolute mind bender

                                        OH and As a foot note try to keep away from using third party applets, javascripts, css files, html designs and fla files you will learn far more from looking through the source seeing what it does and adding a mental note of what each peice of code does

                                        if(object::newbie == stuck){
                                        Ask For Help
                                        }