PHP OO Java Main Method equivalent???

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

    PHP OO Java Main Method equivalent???

    Hey!

    I'm new to OO in PHP but somewhat familiar with this paridigm in
    JAVA....

    So I was wondering if it is possible to have within a PHP script
    something equivalent to a main method as it is possible in JAVA....

    For example:

    class myclass{
    //my class's code
    }

    //Here is where I want to create a main method... or a function that
    gets automatically called when the script is executed... that way this
    "main" method would create instances of "myclass" and use them...


    Cheers!

    Jose

  • e_matthes@hotmail.com

    #2
    Re: PHP OO Java Main Method equivalent???

    On Jun 15, 6:57 am, pelon <pelonbiol...@g mail.comwrote:
    Hey!
    >
    I'm new to OO in PHP but somewhat familiar with this paridigm in
    JAVA....
    >
    So I was wondering if it is possible to have within a PHP script
    something equivalent to a main method as it is possible in JAVA....
    >
    For example:
    >
    class myclass{
    //my class's code
    >
    }
    >
    //Here is where I want to create a main method... or a function that
    gets automatically called when the script is executed... that way this
    "main" method would create instances of "myclass" and use them...
    >
    Cheers!
    >
    Jose

    Have you tried a simple example?

    Comment

    • fel

      #3
      Re: PHP OO Java Main Method equivalent???

      On Jun 15, 9:57 am, pelon <pelonbiol...@g mail.comwrote:
      Hey!
      >
      I'm new to OO in PHP but somewhat familiar with this paridigm in
      JAVA....
      >
      So I was wondering if it is possible to have within a PHP script
      something equivalent to a main method as it is possible in JAVA....

      <?php
      class welcometophp {
      function main(){
      System.out.prin tln("not that different from java, is it?");
      }
      }

      welcometophp::m ain();
      ?>


      >
      For example:
      >
      class myclass{
      //my class's code
      >
      }
      >
      //Here is where I want to create a main method... or a function that
      gets automatically called when the script is executed... that way this
      "main" method would create instances of "myclass" and use them...
      >
      Cheers!
      >
      Jose

      Comment

      • Benjamin

        #4
        Re: PHP OO Java Main Method equivalent???

        On Jun 15, 9:57 am, pelon <pelonbiol...@g mail.comwrote:
        Hey!
        >
        I'm new to OO in PHP but somewhat familiar with this paridigm in
        JAVA....
        >
        So I was wondering if it is possible to have within a PHP script
        something equivalent to a main method as it is possible in JAVA....
        >
        For example:
        >
        class myclass{
        //my class's code
        >
        }
        >
        //Here is where I want to create a main method... or a function that
        gets automatically called when the script is executed... that way this
        "main" method would create instances of "myclass" and use them...
        You can't get away without something outside, but you can do as the
        person above me pointed out: make a static function and call it first
        thing.
        >
        Cheers!
        >
        Jose

        Comment

        • C.

          #5
          Re: PHP OO Java Main Method equivalent???

          On 15 Jun, 15:57, pelon <pelonbiol...@g mail.comwrote:
          Hey!
          >
          I'm new to OO in PHP but somewhat familiar with this paridigm in
          JAVA....
          >
          So I was wondering if it is possible to have within a PHP script
          something equivalent to a main method as it is possible in JAVA....
          >
          First thing is the PHP, unlike Java has first class functions. Second
          thing, is that PHP, like most scripting languages has an implicit
          entry point at the beginning of the invoked file so all you need to do
          is this:

          BOF>>>>>>>>>>>
          <?php

          $obj = new myclass();

          class myclass{
          //my class's code
          }

          ?>
          <<<<<<<<<<<EO F

          Although its generally considered neater to put class definitions in
          their own include file so...

          BOF>>>>>>>>>>>
          <?php

          require_once('m yclass.inc.php' );
          $obj = new myclass();

          ?>
          <<<<<<<<<<<EO F

          HTH

          C.

          Comment

          • astrapils

            #6
            Re: PHP OO Java Main Method equivalent???

            Have you read this?



            pelon wrote:
            Hey!
            >
            I'm new to OO in PHP but somewhat familiar with this paridigm in
            JAVA....
            >
            So I was wondering if it is possible to have within a PHP script
            something equivalent to a main method as it is possible in JAVA....
            >
            For example:
            >
            class myclass{
            //my class's code
            }
            >
            //Here is where I want to create a main method... or a function that
            gets automatically called when the script is executed... that way this
            "main" method would create instances of "myclass" and use them...
            >
            >
            Cheers!
            >
            Jose

            Comment

            Working...