Simple example of how to wirite php using classes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sbettadpur
    New Member
    • Aug 2007
    • 121

    Simple example of how to wirite php using classes

    hi,

    hello friends, i know basic php, i want to use advanced php classes is anybody knows how to write simple example using php classes.

    i want to use this one for listbox::onChan ge class.

    regards
    shiva
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    Check out Classes and Objects at the PHP.net Manual.

    The class you mentioned, listbox, does not exists in PHP.
    It looks more like a .Net class. Where did you find it?

    Comment

    • gregerly
      Recognized Expert New Member
      • Sep 2006
      • 192

      #3
      VERY SIMPLE CLASS

      class.php

      [PHP]class myClass{

      var $message;

      function echoMessage(){
      echo $this->message;
      }

      }[/PHP]

      index.php

      [PHP]include("./path/to/the/class.php");
      $class=new myClass;

      $class->message = "Hello World";
      $class->echoMessage( );

      //Results in "Hello World"[/PHP]

      This is an extremely simple example of OOP and using classes in PHP.

      Greg

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Or in PHP 5:

        [code=php]
        class myClass
        {
        protected $message;

        public function __construct()
        {
        $this->message = 'Hello, World!';
        }

        public function echoMessage()
        {
        echo $this->message;
        }
        }
        [/code]

        Comment

        • gregerly
          Recognized Expert New Member
          • Sep 2006
          • 192

          #5
          Originally posted by pbmods
          Or in PHP 5:

          [code=php]
          class myClass
          {
          protected $message;

          public function __construct()
          {
          $this->message = 'Hello, World!';
          }

          public function echoMessage()
          {
          echo $this->message;
          }
          }
          [/code]
          well done good sir :)

          Comment

          Working...