Using Classes within another class.

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

    Using Classes within another class.

    Ok,

    I have a "form" class, which I am going to use to generate HTML forms.

    I also have a form_input, which I use to generate the individual HTML
    input elements.

    What I want to do is some how manage the instances of the form_input
    class, within the form class. There should be no problem with this, but I
    can't work out how I can store an unspecified number of instances of one
    class within another, is it possible to do something like this, and store
    them in an array?

    $input_array[] = new form_input(some vars...);
    $input_array[] = new form_input(some vars...);
    $input_array[] = new form_input(some vars...);
    $input_array[] = new form_input(some vars...);

    then when I want to do stuff with the individual form elements I can do:

    $input_array[1]->do_some_functi on();
    $input_array[2]->do_some_functi on();

    Or more likely what I would like to do, is use a foreach loop.

    Has anyone done something like this before, and can offer tips?

    Many Thanks,
    Harry
  • Tim Van Wassenhove

    #2
    Re: Using Classes within another class.

    In article <opr71dlf1gsb0v gs@news.btinter net.com>, AJ wrote:[color=blue]
    > Ok,
    >
    > I have a "form" class, which I am going to use to generate HTML forms.
    >
    > I also have a form_input, which I use to generate the individual HTML
    > input elements.
    >
    > What I want to do is some how manage the instances of the form_input
    > class, within the form class. There should be no problem with this, but I
    > can't work out how I can store an unspecified number of instances of one
    > class within another, is it possible to do something like this, and store
    > them in an array?[/color]

    array_push ?



    --

    Comment

    • AJ

      #3
      Re: Using Classes within another class.

      On 15 May 2004 10:25:16 GMT, Tim Van Wassenhove <euki@pi.be> wrote:
      [color=blue]
      > In article <opr71dlf1gsb0v gs@news.btinter net.com>, AJ wrote:[color=green]
      >> Ok,
      >>
      >> I have a "form" class, which I am going to use to generate HTML forms.
      >>
      >> I also have a form_input, which I use to generate the individual HTML
      >> input elements.
      >>
      >> What I want to do is some how manage the instances of the form_input
      >> class, within the form class. There should be no problem with this, but
      >> I
      >> can't work out how I can store an unspecified number of instances of one
      >> class within another, is it possible to do something like this, and
      >> store
      >> them in an array?[/color]
      >
      > array_push ?[/color]

      Duh!

      Sorry, I'm having one of those days!! It turns out, what I was trying is
      possible - but I had cocked up some syntax along the way.

      Thanks,
      H

      Comment

      Working...