[PHP] Q on Class and EXTEND

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default RE: [PHP] Q on Class and EXTEND

    > -----Original Message-----
    > From: Matt Matijevich [mailto:matijevich@alliancetechnologies.net]
    > Sent: Wednesday, September 03, 2003 11:21 AM
    > To: [email]php-general@lists.php.net[/email]; [email]jsWalter@torres.ws[/email]
    > Subject: Re: [PHP] Q on Class and EXTEND
    >
    >
    > I dont know much about classes, but dont you want
    >
    > $a = new THECHILD('walter'); //so you can access $a->abc
    >
    > instead of
    >
    > $a = new THEPARENT ('walter');
    No, I'm wanting to EXTEND the orginal class.

    meaning, my THECHILD class efines new methods/properties, and I want it used
    as if it was part of the orginal THEPARENT Class.

    Me just being picky.

    Walter
    Jswalter Guest

  2. Similar Questions and Discussions

    1. #38947 [NEW]: Unable to extend mysqli class properly without causing various fatal errors
      From: rk at yes-co dot nl Operating system: Debian PHP version: 5.1.6 PHP Bug Type: MySQLi related Bug description: Unable...
    2. Extend Date Class Flex 2 Beta 3
      I want to add some methods to the Date class, like beginOfMonth / endOfMonth which returns the first millisecond and last millisecond of the month...
    3. Best way to extend contribute
      I have an application that extends the menus and toolbars of Contribute 3.11. The only way I found how to do this is to have my installer...
    4. Extend the DataGrid 2
      If I want to add three buttons to the datagrid then what should be the best way to go about it? Extend the DataGrid or create a composite control...
    5. Q on Class and EXTEND
      I found a piece of code in the docs, and thought it was a way to EXTEND a Class with new properties tha cna be accessed from original Class Object....
  3. #2

    Default Re: [PHP] Q on Class and EXTEND

    jsWalter wrote:
    >>-----Original Message-----
    >>From: Matt Matijevich [mailto:matijevich@alliancetechnologies.net]
    >>
    >>I dont know much about classes, but dont you want
    >>
    >>$a = new THECHILD('walter'); //so you can access $a->abc
    >>
    >>instead of
    >>
    >>$a = new THEPARENT ('walter');
    >
    >
    > No, I'm wanting to EXTEND the orginal class.
    >
    > meaning, my THECHILD class efines new methods/properties, and I want it used
    > as if it was part of the orginal THEPARENT Class.
    >
    > Me just being picky.
    It doesn't work that way, exactly. The child class can define new
    methods and properties, but you must make an instance of the child
    class, which will include the methods/properties from the parent, and
    the new ones you have written.

    If I'm understanding you correctly, you could rename you parent class to
    child, name the child class the same as your parent and have the "old
    class" extend the "new class" you've written. You code should then work
    the same, but have the new methods/properties available.

    --
    ---John Holmes...

    Amazon Wishlist: [url]www.amazon.com/o/registry/3BEXC84AB3A5E/[/url]

    php|architect: The Magazine for PHP Professionals – [url]www.phparch.com[/url]
    John W. Holmes Guest

  4. #3

    Default Re: [PHP] Q on Class and EXTEND


    <-- snip -->
    > > I dont know much about classes, but dont you want
    > >
    > > $a = new THECHILD('walter'); //so you can access $a->abc
    > >
    > > instead of
    > >
    > > $a = new THEPARENT ('walter');
    >
    > No, I'm wanting to EXTEND the orginal class.
    >
    > meaning, my THECHILD class efines new methods/properties, and I want it
    used
    > as if it was part of the orginal THEPARENT Class.
    >
    > Me just being picky.
    >
    > Walter
    <-- snip -->

    walter you want to do a declaration in the class that you want to use the
    base class in ie


    when you declare your child class

    class Web_child extends WEB_parent
    {
    -- your new and extended code here
    }
    Chris Sherwood Guest

  5. #4

    Default Re: [PHP] Q on Class and EXTEND

    "John W. Holmes" <holmes072000@charter.net> wrote in message
    news:3F561CF1.3000100@charter.net...
    > jsWalter wrote:
    > > I'm wanting to EXTEND the orginal class.
    > >
    > > meaning, my THECHILD class efines new methods/properties, and I want it
    used
    > > as if it was part of the orginal THEPARENT Class.
    > >
    > > Me just being picky.
    >
    > It doesn't work that way, exactly. The child class can define new
    > methods and properties, but you must make an instance of the child
    > class, which will include the methods/properties from the parent, and
    > the new ones you have written.
    >
    > If I'm understanding you correctly, you could rename you parent class to
    > child, name the child class the same as your parent and have the "old
    > class" extend the "new class" you've written. You code should then work
    > the same, but have the new methods/properties available.
    What I am trying to do is EXTEND the PEAR::Auth Class with new properties
    and methods.

    But I still want to use the original instantiation call...

    $myAuth =& Auth();

    So, I don't think I can rename the orginal Class in this case.

    I'm just being particular.

    Or do I have to create my new EXTENDED Class and then add code to PEAR::Auth
    to make it work as if it is always just Auth? (I was told I could not do
    that)

    Thanks

    Walter
    Jswalter Guest

  6. #5

    Default Re: [PHP] Q on Class and EXTEND

    > What I am trying to do is EXTEND the PEAR::Auth Class with new properties
    > and methods.
    Ok.
    > But I still want to use the original instantiation call...
    > $myAuth =& Auth();
    Which is instantiating the parent class.
    From what I understand of your question, you are wanting to instantiate the
    parent which, in turn, somehow calls upon (or instantiats) the child simply
    because the child EXTENDS the parent? Is that correct?
    If so, I don't believe this type of functionality/feature exists in any language,
    much less PHP. Am I wrong?

    Chris
    Chris Boget Guest

  7. #6

    Default Re: [PHP] Q on Class and EXTEND

    On Wed, 3 Sep 2003 10:05:46 -0700
    "Chris Sherwood" <csherwood@nortialearning.com> wrote:
    >
    > <-- snip -->
    > > > I dont know much about classes, but dont you want
    > > >
    > > > $a = new THECHILD('walter'); //so you can access $a->abc
    > > >
    > > > instead of
    > > >
    > > > $a = new THEPARENT ('walter');
    > >
    > > No, I'm wanting to EXTEND the orginal class.
    > >
    > > meaning, my THECHILD class efines new methods/properties, and I
    > > want it
    > used
    > > as if it was part of the orginal THEPARENT Class.
    > >
    > > Me just being picky.
    > >
    > > Walter
    > <-- snip -->
    >
    > walter you want to do a declaration in the class that you want to
    > use the base class in ie
    >
    >
    > when you declare your child class
    >
    > class Web_child extends WEB_parent
    > {
    > -- your new and extended code here
    > }
    >
    and then ... to access the class methods and variables of the
    parent, you do it through the child.

    class THEPARENT
    var $originalthis;
    function THEPARENT(){
    }
    }

    class THECHILD extends THEPARENT
    var $this;
    function THECHILD($that) {
    $this->this = $that;
    }
    }

    // outside the class
    $clss = new THECHILD($thatvar);
    $clss->originalthis = 'how about that';

    --
    Raquel
    ================================================== ==========
    Let no man imagine that he has no influence. Whoever he may be, and
    wherever he may be placed, the man who thinks becomes a light and a
    power.
    --Henry George

    --
    Raquel
    ================================================== ==========
    Let no man imagine that he has no influence. Whoever he may be, and
    wherever he may be placed, the man who thinks becomes a light and a
    power.
    --Henry George
    Raquel Rice Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139