Fatal error: Cannot re-assign $this in How can i fix it ?

Discussion in 'PHP' started by leandar, May 22, 2009.

  1. #1
    i was trying to install "Shiichan Anonymous BBS" then i got this error

    Fatal error: Cannot re-assign $this in /home/content/p/o/o/site/html/4chan/admin.php on line 557

    line 557 here

    i am using phpbb5
     
    leandar, May 22, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Don't use the variable name $this. It is reserved, and php thinks you're trying to do something else.
     
    jestep, May 22, 2009 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    this in PHP is simliar to this in C++. Try using different variable names.

    Peace,
     
    Barti1987, May 22, 2009 IP
  4. leandar

    leandar Well-Known Member

    Messages:
    3,929
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    170
    #4
    hmm ... i don't know anything about php, please you guys explain me how can i fix it ..

    even i don't know whats variable ...
     
    leandar, May 22, 2009 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    Where did you get the script from?
     
    jestep, May 22, 2009 IP
  6. leandar

    leandar Well-Known Member

    Messages:
    3,929
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    170
    #6
    leandar, May 22, 2009 IP
  7. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #7
    $this is a keyword that refers to the class from which it's called from. In the code
    else foreach ($board as $this) { 
    Code (markup):
    replace $this with another variable. When you do that, you must also replace $this within the { and } brackets of the foreach loop.
     
    xlcho, May 22, 2009 IP
  8. leandar

    leandar Well-Known Member

    Messages:
    3,929
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    170
    #8
    another variable ? where ...

    this is the admin.php look that 557 line
     

    Attached Files:

    leandar, May 22, 2009 IP
  9. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #9
    Search and replace all occurrences $this to $myVar.

    Peace,
     
    Barti1987, May 22, 2009 IP
    leandar likes this.
  10. leandar

    leandar Well-Known Member

    Messages:
    3,929
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    170
    #10
    Hahaha ... thank you thank you ... its working :):D:p
     
    leandar, May 22, 2009 IP
  11. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #11
    Something seems seriously wrong here. That's just one of those errors you shouldn't ever be getting in a script you're not actively working on yourself.
     
    joebert, May 24, 2009 IP
  12. felluahill

    felluahill Peon

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Agreed, any moderate PHP programmer would not make that mistake.

    And when they say replace it with another variable do something like this:

    else foreach ($board as $subBoard) { 
    Code (markup):
    Then replace every instance of $this in the following code with $subBoard.
     
    felluahill, May 24, 2009 IP
  13. leandar

    leandar Well-Known Member

    Messages:
    3,929
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    170
    #13
    thanks you guys for the help, problem solved. :)
     
    leandar, May 24, 2009 IP