Objects in PHP

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

    Objects in PHP

    Im using objects in PHP for the first time and have a question about
    the following script.

    $new_grad = new graduate();
    $new_grad->set_fn($_SESSI ON['first_name']);
    $new_grad->set_sn($_SESSI ON['surname']);
    $new_grad->set_username($ _SESSION['username']);
    $new_grad->set_password($ _SESSION['password']);
    //etc

    The sript is used to set up user accounts when they sign up for my
    system.
    HOWEVER I am concerned about the following scenario. Say if two or
    more users are setting up accounts at roughly the same time.
    The first person presses 'submit' so

    $new_grad = new graduate();

    gets executed.
    But if a second or so later another person presses submit the same
    line of code will get executed so we will either have two objects with
    the same name or the second object will replace the first.
    Neither of which is desirable so how could I avoid this?
  • Pedro Graca

    #2
    Re: Objects in PHP

    David wrote:[color=blue]
    > The first person presses 'submit' so
    >
    > $new_grad = new graduate();
    >
    > gets executed.
    > But if a second or so later another person presses submit the same
    > line of code will get executed so we will either have two objects with
    > the same name or the second object will replace the first.
    > Neither of which is desirable so how could I avoid this?[/color]

    Each person gets 'his' own php.
    Imagine each object name is prefixed with the access id.

    For the first person php creates person1.new_gra d
    and then for the second it creates person2.new_gra d

    When you do <?php $new_grad->save(); ?> it's like you knew which person
    was accessing at that time and the same as
    <?php $person<whateve r>.new_grad->save(); ?>

    In short, don't worry about that :)

    It's just the same for objects as for 'normal' variables ... have you
    worried about that for 'normal' variables before?
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • David

      #3
      Re: Objects in PHP

      Thanks a lot, I had a feeling (hoping:-) it was something like that,
      just had a sudden panic thats all when I thought everything would
      crash due to my lack of knowledge for objects!
      [color=blue]
      > Each person gets 'his' own php.
      > Imagine each object name is prefixed with the access id.
      >
      > For the first person php creates person1.new_gra d
      > and then for the second it creates person2.new_gra d
      >
      > When you do <?php $new_grad->save(); ?> it's like you knew which person
      > was accessing at that time and the same as
      > <?php $person<whateve r>.new_grad->save(); ?>
      >
      > In short, don't worry about that :)
      >
      > It's just the same for objects as for 'normal' variables ... have you
      > worried about that for 'normal' variables before?[/color]

      Comment

      • Alvaro G Vicario

        #4
        Re: Objects in PHP

        *** David wrote/escribió (8 Jan 2004 08:08:08 -0800):[color=blue]
        > But if a second or so later another person presses submit the same
        > line of code will get executed so we will either have two objects with
        > the same name or the second object will replace the first.
        > Neither of which is desirable so how could I avoid this?[/color]

        <?
        echo $name;
        $name='John';
        ?>

        Open several browser Windows and execute the script as many times as you
        want. Will you ever get 'John' printed? With objects it's just the same.


        --
        --
        -- Álvaro G. Vicario - Burgos, Spain
        --

        Comment

        • Erwin Moller

          #5
          Re: Objects in PHP

          David wrote:
          [color=blue]
          > Thanks a lot, I had a feeling (hoping:-) it was something like that,
          > just had a sudden panic thats all when I thought everything would
          > crash due to my lack of knowledge for objects!
          >[/color]

          Don't Panic, get the Hitch Hikers Guide To The Galaxy pronto at your local
          bookstore.

          Comment

          • Dan Tripp

            #6
            OT: Re: Objects in PHP

            Erwin Moller wrote:
            [color=blue]
            > David wrote:
            >
            >[color=green]
            >>Thanks a lot, I had a feeling (hoping:-) it was something like that,
            >>just had a sudden panic thats all when I thought everything would
            >>crash due to my lack of knowledge for objects!
            >>[/color]
            >
            >
            > Don't Panic, get the Hitch Hikers Guide To The Galaxy pronto at your local
            > bookstore.[/color]


            Don't just get the first book, get the whole series! There's a nice
            edition that has all the books bound in one. 'tis cheaper than buying
            them individually. =)

            Regards,

            - Dan

            Comment

            Working...