SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need help understanding code

    I am trying to figure out why an old PHP code doesn't work as expected. The following line puzzles me:

    Code:
    $this = new $class($i!=$step);
    In the above code,
    Code:
    $class=Step;
    $i=2;
    $step=2;
    So does the line mean:
    Code:
    $this = new Step;
    But there is no class Step, only Step1, Step2, etc.

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,148
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    I'm a little confused. Are you asking why the code isn't working when you think it should, or why the code is working when you think it shouldn't?

    And to answer your question either way, we'll probably need to see more of the actual code. The code you've shown us would not work, and that's to be expected.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am just asking what's going on on that line of code (I mentioned what variables contain).

    And yes, it actually works. I was surprised too.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's PHP 4 btw.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I made a mistake. Here is the correction:
    Code:
    $class=Step2;//<---
    $i=2;
    $step=2
    For some reason, class Step4 is created by this line:
    Code:
    $this = new $class($i!=$step);
    Could the concatenation ('.') operator be skipped in PHP 4? Has anybody seen anything like this?


Bookmarks

Posting Permissions

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