OO PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Smitro

    OO PHP

    Hi all,

    I have spent the last couple of days getting my code up to scratch with
    PHP 5 and MySQL 5. (I still don't quite understand why we had to change
    to mysqli from mysql)

    Just a question, Object Orientated PHP? Is it the way that PHP is
    heading, or is it just an addon for those that want to use it.

    I started using php because to me it made so much sence. When I look at
    the example of Object Orientated PHP I get totally lost. Do I have to
    start looking at moving all my code this way, or is this just an addon
    for those that are use to coding in this way? What are my chances of
    running procedual code in PHP 6?
  • Erwin Moller

    #2
    Re: OO PHP

    Smitro wrote:
    [color=blue]
    > Hi all,
    >
    > I have spent the last couple of days getting my code up to scratch with
    > PHP 5 and MySQL 5. (I still don't quite understand why we had to change
    > to mysqli from mysql)
    >
    > Just a question, Object Orientated PHP? Is it the way that PHP is
    > heading, or is it just an addon for those that want to use it.
    >
    > I started using php because to me it made so much sence. When I look at
    > the example of Object Orientated PHP I get totally lost. Do I have to
    > start looking at moving all my code this way, or is this just an addon
    > for those that are use to coding in this way? What are my chances of
    > running procedual code in PHP 6?[/color]

    Hi,

    Stay cool. :-)
    You CAN use OO if you want, but nobody is forcing you to do so.
    Many hackers like PHP the way it is, and do not use OO.

    Because OO offer some very serious advantages, you can expect to see more
    OO-PHP-code, but of course it is up to you if you want to use it.

    And PHP is not heading in a direction that forces you to use OO, it is just
    offering you the option.

    Mind however that many usefull add-ons, like PEAR, are coded in an OO
    fashion. If you find you have some time left, use it to study OO.
    PHP's implementation of OO is easy to learn (compared to Java eg), and you
    might find yourself in the future in the situation you see that
    very-handy-impossible-to-resist-package, but it uses OO.


    Regards,
    Erwin Moller

    Comment

    • Oliver Grätz

      #3
      Re: OO PHP

      No question: You will be able to use procedural code with PHP6!

      The developers of PHP are well aware that man people prefer this way of
      programming _and_ they want to ensure that clean PHP4 code will be able
      to run on PHP6 with little to no modifications. Some of the developers
      themselves swear by the procedural way!

      Anyway: I prefer OOP. In my early days of PHP I couldn't understand the
      need for classes and objects in a language where your program only lives
      for a couple of seconds or milliseconds, but now my code base has grown
      and classes are _the_ way of easily managing such a lot of code.

      And objects are nice:

      $meeting_id=14;
      $m=new DB_Meeting($mee ting_id);
      foreach ($m->allParticipant s as $person)
      {
      mail(
      $person['email'],
      'Invitation to the meeting "'.$m['topic'].'"',
      'Dear '.$person['nick']', you are invited!'
      );
      }

      This fetches all the records from the database and iterates through them
      without any need for SQL on my side.

      OLLi

      Comment

      • Malcolm Dew-Jones

        #4
        Re: OO PHP

        Erwin Moller (since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om) wrote:
        : Smitro wrote:

        : > Hi all,
        : >
        : > I have spent the last couple of days getting my code up to scratch with
        : > PHP 5 and MySQL 5. (I still don't quite understand why we had to change
        : > to mysqli from mysql)
        : >
        : > Just a question, Object Orientated PHP? Is it the way that PHP is
        : > heading, or is it just an addon for those that want to use it.
        : >
        : > I started using php because to me it made so much sence. When I look at
        : > the example of Object Orientated PHP I get totally lost. Do I have to
        : > start looking at moving all my code this way, or is this just an addon
        : > for those that are use to coding in this way? What are my chances of
        : > running procedual code in PHP 6?

        : Hi,

        : Stay cool. :-)
        : You CAN use OO if you want, but nobody is forcing you to do so.
        : Many hackers like PHP the way it is, and do not use OO.

        : Because OO offer some very serious advantages, you can expect to see more
        : OO-PHP-code, but of course it is up to you if you want to use it.

        : And PHP is not heading in a direction that forces you to use OO, it is just
        : offering you the option.

        : Mind however that many usefull add-ons, like PEAR, are coded in an OO
        : fashion.

        For the most part, you don't need to "know" OO to use OO libraries.

        To use most libraries, OO is just a syntax,

        $value_returned _earlier->useful_functio n_name(my,args, go,here);

        Someone said that they like OO, but you have to realize that at some point
        in the code, every OO program does plain old procedural programming.

        If you are tying things together, and they happen one step at a time, then
        procedural code is the thing you need.

        Many tasks are best solved one step at a time, possibly using libraries
        (which may be OO) to take care of the arcane details.

        Comment

        Working...