Double Dot Means what ::

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

    Double Dot Means what ::

    Hi friends

    I'm still exploring in PHP programming with little knowledge on C ..
    the mother of programming language..

    Just wonder .. some times we will see some pepole use :: singn in
    their code
    and what it mean ?


    for e.g Get::message ; <-- what the :: means.. is it some conditional
    statement
    because i saw a lot in Pear stlyle of coding..

  • Chris Hope

    #2
    Re: Double Dot Means what ::

    badz wrote:
    [color=blue]
    > I'm still exploring in PHP programming with little knowledge on C ..
    > the mother of programming language..
    >
    > Just wonder .. some times we will see some pepole use :: singn in
    > their code
    > and what it mean ?
    >
    > for e.g Get::message ; <-- what the :: means.. is it some conditional
    > statement
    > because i saw a lot in Pear stlyle of coding..[/color]

    It's a way of calling a method in a class without actually creating an
    object; but because you haven't created the object you don't have
    access to any of the properties that might have already been set.
    Example:

    class foo {

    var $abc = '123';

    function bar() {
    print $this->abc;
    }

    }

    You can call the method bar() like this:

    $foo = new foo();
    $foo->bar();

    OR like this:

    foo::bar();

    Calling it like $foo->bar(); will print out '123' but foo::bar(); will
    not. And depending on your level of error reporting, calling foo::bar()
    in the above example will show an "undefined variable" error message.

    --
    Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

    Comment

    • Senator Jay Billington Bulworth

      #3
      Re: Double Dot Means what ::

      "badz" <badz22@gmail.c om> wrote in news:1110097485 .547798.187980
      @g14g2000cwa.go oglegroups.com:
      [color=blue]
      > Hi friends
      >
      > I'm still exploring in PHP programming with little knowledge on C ..
      > the mother of programming language..
      >
      > Just wonder .. some times we will see some pepole use :: singn in
      > their code
      > and what it mean ?
      >
      >
      > for e.g Get::message ; <-- what the :: means.. is it some conditional
      > statement
      > because i saw a lot in Pear stlyle of coding..[/color]

      :: is the scope resolution operator, part of PHP's object oriented
      implementation. It allows you to access properties and methods of a
      class, even if you haven't instantiated a member of the class. Have a
      look at:

      <http://www.php.net/manual/en/keyword.paamayi m-nekudotayim.php >

      hth


      --

      Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fu ng.arg');
      --------------------------|---------------------------------
      <http://www.phplabs.com/> | PHP scripts, webmaster resources

      Comment

      • Chris Hope

        #4
        Re: Double Dot Means what ::

        Chris Hope wrote:
        [color=blue]
        > badz wrote:
        >[color=green]
        >> I'm still exploring in PHP programming with little knowledge on C ..
        >> the mother of programming language..
        >>
        >> Just wonder .. some times we will see some pepole use :: singn in
        >> their code
        >> and what it mean ?
        >>
        >> for e.g Get::message ; <-- what the :: means.. is it some
        >> conditional statement
        >> because i saw a lot in Pear stlyle of coding..[/color]
        >
        > It's a way of calling a method in a class without actually creating an
        > object; but because you haven't created the object you don't have
        > access to any of the properties that might have already been set.
        > Example:
        >
        > class foo {
        >
        > var $abc = '123';
        >
        > function bar() {
        > print $this->abc;
        > }
        >
        > }
        >
        > You can call the method bar() like this:
        >
        > $foo = new foo();
        > $foo->bar();
        >
        > OR like this:
        >
        > foo::bar();
        >
        > Calling it like $foo->bar(); will print out '123' but foo::bar(); will
        > not. And depending on your level of error reporting, calling
        > foo::bar() in the above example will show an "undefined variable"
        > error message.[/color]

        And the manual has some info about it here:
        PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


        --
        Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

        Comment

        • NSpam

          #5
          Re: Double Dot Means what ::

          Senator Jay Billington Bulworth wrote:[color=blue]
          > "badz" <badz22@gmail.c om> wrote in news:1110097485 .547798.187980
          > @g14g2000cwa.go oglegroups.com:
          >
          >[color=green]
          >>Hi friends
          >>
          >>I'm still exploring in PHP programming with little knowledge on C ..
          >>the mother of programming language..
          >>
          >>Just wonder .. some times we will see some pepole use :: singn in
          >>their code
          >>and what it mean ?
          >>
          >>
          >>for e.g Get::message ; <-- what the :: means.. is it some conditional
          >>statement
          >>because i saw a lot in Pear stlyle of coding..[/color]
          >
          >
          > :: is the scope resolution operator, part of PHP's object oriented
          > implementation. It allows you to access properties and methods of a
          > class, even if you haven't instantiated a member of the class. Have a
          > look at:
          >
          > <http://www.php.net/manual/en/keyword.paamayi m-nekudotayim.php >
          >
          > hth
          >
          >[/color]
          essentially its a pseuedonym for $this->

          Comment

          • Janwillem Borleffs

            #6
            Re: Double Dot Means what ::

            NSpam wrote:[color=blue]
            > essentially its a pseuedonym for $this->[/color]

            Not really, since this expects you to have created an instance of an object,
            while Class::method can be used without prior object instantiation.. .


            JW



            Comment

            • Michael Fesser

              #7
              Re: Double Dot Means what ::

              .oO(NSpam)
              [color=blue]
              >essentially its a pseuedonym for $this->[/color]

              Nope.

              Micha

              Comment

              • badz

                #8
                Re: Double Dot Means what ::

                ok thank guys..
                so its called Scope Resolution Operator . and widely used in OOP inside
                PHP

                Comment

                • ggg@gg.com

                  #9
                  Re: Double Dot Means what ::

                  In article <1110097485.547 798.187980@g14g 2000cwa.googleg roups.com>,
                  badz22@gmail.co m says...[color=blue]
                  > Hi friends
                  >
                  > I'm still exploring in PHP programming with little knowledge on C ..
                  > the mother of programming language..
                  >
                  > Just wonder .. some times we will see some pepole use :: singn in
                  > their code
                  > and what it mean ?
                  >
                  >
                  > for e.g Get::message ; <-- what the :: means.. is it some conditional
                  > statement
                  > because i saw a lot in Pear stlyle of coding..
                  >
                  >[/color]

                  You could think of it as, just calling that function w/o instantiating
                  the class that it's in.

                  Comment

                  Working...