Class public function

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

    Class public function

    I am running PHP version 4.3.11-dev:

    The class as defined below does not work:

    <?php

    class hello {
    public function printHello() {
    echo "HELLO";
    }
    }

    $obj = new hello;

    $obj->printHello() ; // does NOT print hello

    ?>

    When i delete the 'public' keyword then the above works ok!

    Is it maybe because 4.3.11-dev probably does not fully support classes?

    Marcel



  • Etienne Marais

    #2
    Re: Class public function

    Marcel wrote:
    [color=blue]
    > When i delete the 'public' keyword then the above works ok!
    >
    > Is it maybe because 4.3.11-dev probably does not fully support classes?
    >
    > Marcel[/color]

    PHP Prior to version 5 does not
    support access specifiers.

    --
    Etienne Marais
    Cosmic Link
    South Africa

    Comment

    • Marcel

      #3
      Re: Class public function

      [color=blue]
      > PHP Prior to version 5 does not
      > support access specifiers.
      >
      > --[/color]

      Ok thanks, but is it a good idea then to build classes in PHP versions prior
      to ver. 5 ?

      Marcel


      Comment

      • Etienne Marais

        #4
        Re: Class public function

        Marcel wrote:
        [color=blue]
        >[color=green]
        >> PHP Prior to version 5 does not
        >> support access specifiers.
        >>
        >> --[/color]
        >
        > Ok thanks, but is it a good idea then to build classes in PHP versions
        > prior to ver. 5 ?
        >
        > Marcel[/color]

        If you foresee using PHP 5 in the future,
        preferably not. If you are starting clean,
        now is the best time to jump onto the PHP 5
        bandwagon (and I'd be looking on jealously).

        --
        Etienne Marais
        Cosmic Link
        South Africa

        Comment

        • Etienne Marais

          #5
          Re: Class public function

          Marcel wrote:
          [color=blue]
          >[color=green]
          >> PHP Prior to version 5 does not
          >> support access specifiers.
          >>
          >> --[/color]
          >
          > Ok thanks, but is it a good idea then to build classes in PHP versions
          > prior to ver. 5 ?
          >
          > Marcel[/color]

          Actually it depends on yourself.

          Are you strongly concerned with upward compatibility
          or just curious if php 4 classes are 'even viable' ?

          I have had a lot of fun with 'OO oriented PHP 4' but
          an equal amount of misery due to unexpected limited
          consistency and stability.

          --
          Etienne Marais
          Cosmic Link
          South Africa

          Comment

          • Marcel

            #6
            Re: Class public function

            [color=blue]
            >
            > PHP Prior to version 5 does not
            > support access specifiers.
            >
            > --[/color]

            Thanks for your advice Etienne,

            Most PHP classes on the web i've seen do not use access-specifiers at
            all.... is bthat to make them backwards compatible with earlier versions of
            PHP.

            What's PHP5's status right now? Is it allready broadly in use by the PHP
            community or is it still relatively new?

            Marcel


            Comment

            • Colin Fine

              #7
              Re: Class public function

              Marcel wrote:[color=blue][color=green]
              >>PHP Prior to version 5 does not
              >>support access specifiers.
              >>
              >>--[/color]
              >
              >
              > Thanks for your advice Etienne,
              >
              > Most PHP classes on the web i've seen do not use access-specifiers at
              > all.... is bthat to make them backwards compatible with earlier versions of
              > PHP.
              >
              > What's PHP5's status right now? Is it allready broadly in use by the PHP
              > community or is it still relatively new?
              >
              > Marcel
              >
              >[/color]
              Both PHP 4 and PHP 5 are in use.

              Having made the somewhat painful transition, I would recommend anybody
              starting now to use PHP 5, especially if they think OO.

              The OO model in PHP 4 is broken, not to put too fine a point on it.

              Having said that, I suspect that not too many systems are using access
              specifiers yet, because without 'friend classes', or some equivalent
              mechanism, its usefulness is limited.

              Colin

              Comment

              • Alvaro G. Vicario

                #8
                Re: Class public function

                *** Marcel escribió/wrote (Wed, 7 Dec 2005 12:16:32 +0100):[color=blue]
                > What's PHP5's status right now? Is it allready broadly in use by the PHP
                > community or is it still relatively new?[/color]

                In Unix-like boxes is difficult to upgrade PHP version. You have to compile
                from sources, break package system and handle lots of library
                incompatibiliti es. Also, Linux distros designed for servers tend to test
                software for quite long before releasing it (for instance, current version
                of Red Hat Enterprise Linux includes PHP 4.3.9 if I recall correctly).

                So it's rather common to find old versions out there. Choosing a
                development version is more a question of "where am I going to run my
                scripts?".

                In general, I tend to ignore the latest when I do web development. You
                often depend on computers you can't control and are slow to upgrade (think
                on CSS and web browsers). And it's also pretty common that fashionable
                technologies of today are simply death three years later. I still regret
                having learnt ASP ;-)


                --
                -+ Álvaro G. Vicario - Burgos, Spain
                ++ http://bits.demogracia.com es mi sitio para programadores web
                +- http://www.demogracia.com es mi web de humor libre de cloro
                --

                Comment

                Working...