Parent Objects

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

    #16
    Re: Parent Objects

    Michael Fesser wrote:
    '->' requires an instance of a class
    That's where I got futzed up.
    I didn't realize that was a wordy way of saying "object".
    That's right, right?

    Comment

    • Michael Fesser

      #17
      Re: Parent Objects

      ..oO(Sanders Kaufman)
      >Michael Fesser wrote:
      >
      >'->' requires an instance of a class
      >
      >That's where I got futzed up.
      >I didn't realize that was a wordy way of saying "object".
      >That's right, right?
      Yep. ;)

      Micha

      Comment

      • Sanders Kaufman

        #18
        Re: Parent Objects

        Michael Fesser wrote:
        An object is an incarnation of a class, which itself is more or less
        just a "blueprint" for creating objects.
        Man, you guys are really helping out here. I wrote "Teach
        Yourself ActiveX Programming in 21 Days" about 10 years ago.

        Since then, a bout with menningitis killed off a lot of what I
        knew about OOP.

        You're really helping me get it back.

        Comment

        • Rik

          #19
          Re: Parent Objects

          Sanders Kaufman wrote:
          Rik wrote:
          >Sanders Kaufman wrote:
          >
          >>Where would I use "::"?
          >>
          >You wouldn't, as it are all objects, and not classes. You'd only
          >need it if your class extended another class and you wished to call
          >a parents method.
          >>
          >http://www.php.net/manual/en/languag...ekudotayim.php
          >
          OH! So if my class has a method, and then another class extends
          the class and overrides(?) the method, I can call the original
          method with "::"?
          Yup, you've got it :-).
          --
          Rik Wasmus


          Comment

          • Rik

            #20
            Re: Parent Objects

            Sanders Kaufman wrote:
            Toby Inkster wrote:
            >
            ><?php
            >include "Widget.class.p hp";
            >echo Widget::FOO;
            >>>
            >>
            >Versus:
            >>
            ><?php
            >include "Widget.class.p hp";
            >$my_widget = new Widget();
            >echo $my_widget->FOO;
            >>>
            >
            >
            It means that I can call the CLASS method, without
            instantiating(? ) an object, right?
            >
            Man, oh man, that could be real handy for my classes that don't
            do too much stuff in the constructor!
            >
            Wait... I guess I shouldn't assume here. So I'll ask - when I
            call a class method with "::", it won't fire up the constructor,
            will it?
            It won't, and furthermore, $this will not available. For most cases, you
            can use self::
            --
            Rik Wasmus


            Comment

            • raghuanandy@gmail.com

              #21
              Re: Parent Objects


              Sanders Kaufman wrote:
              Michael Fesser wrote:
              .oO(Sanders Kaufman)
              I read that, but I'm still a little confused.
              When I use a class's methods and such, I've been using "->".
              But it seems like this "::" is used the same way.
              What's the difference?
              $someObject->method()
              someClass::stat icMethod()

              '->' requires an instance of a class, whereas '::' is used to call
              static class methods or constants without having an object. Additionally
              it's used to call inherited methods.
              >
              D'oh!
              I thought I had it - but then you said something about static stuff.
              And I think I'm futzed up about Object v. Class here.
              >
              So let's see if I've got it better this way:
              >
              I call my OBJECT methods with "->".
              I call my CLASS methods with "::".
              >
              Ja?
              Right
              <?
              class A{

              public static $a = 'Hello';
              public $b ='World';

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

              public function NonStatic()
              {
              print "\nHere value of b is: ".$this->b;
              //Static members can be accessed though within object methods
              print "\nA value is: ".self::$a;
              }

              public static function StaticMethod()
              {
              print "\n A value is: ".self::$a;

              //This will not work, cannot access object variables(membe rs) within
              Static methods
              //print "\n B value is : ".$this->b;
              }
              } //end class


              $obj1 = new A();

              A::StaticMethod ();

              $obj1->NotStatic();

              ?>

              Hope this clarifes

              Comment

              • Toby Inkster

                #22
                Re: Parent Objects

                Sanders Kaufman wrote:
                It means that I can call the CLASS method, without
                instantiating(? ) an object, right?
                Yep -- and that allows you to use classes as a handy substitute for
                namespaces (something PHP sadly lacks right now).

                --
                Toby A Inkster BSc (Hons) ARCS
                Contact Me ~ http://tobyinkster.co.uk/contact

                Comment

                • Sanders Kaufman

                  #23
                  Re: Parent Objects

                  Toby Inkster wrote:
                  Sanders Kaufman wrote:
                  >
                  >It means that I can call the CLASS method, without
                  >instantiating( ?) an object, right?
                  >
                  Yep -- and that allows you to use classes as a handy substitute for
                  namespaces (something PHP sadly lacks right now).
                  Name whatses?

                  Comment

                  • MF

                    #24
                    Re: Parent Objects


                    Sanders Kaufman wrote:
                    Toby Inkster wrote:
                    Sanders Kaufman wrote:
                    It means that I can call the CLASS method, without
                    instantiating(? ) an object, right?
                    Yep -- and that allows you to use classes as a handy substitute for
                    namespaces (something PHP sadly lacks right now).
                    >
                    Name whatses?
                    This site gives a good explanation of Namespaces:


                    Comment

                    • Sanders Kaufman

                      #25
                      Re: Parent Objects

                      MF wrote:
                      Sanders Kaufman wrote:
                      >Toby Inkster wrote:
                      >>Yep -- and that allows you to use classes as a handy substitute for
                      >>namespaces (something PHP sadly lacks right now).
                      >Name whatses?
                      This site gives a good explanation of Namespaces:
                      http://en.wikipedia.org/wiki/Namespa...ter_science%29
                      Well that explained it, but man that was some awkward language!
                      I seem to remember a journalism instructor telling us that it's
                      bad form to use a word to define itself. Now I see why!

                      Comment

                      Working...