CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    1,689

    What was the purpose of this design?

    In every other OOP language, you are guaranteed that 'this' is going to be of the type of class the code is in (minus if you do dumb typecasting of course.) Why on earth would PHP go against that? Are there any other places besides iterations where $this might not be valid?

    Luckily the class I am wording with is a final one, so I can just check the name of the class type, but what if I were to use polymorphism?

    Code:
    	   public function valid() { 
    		  if (get_class($this) == 'subModuleList'){  //***?  Goes against 30 years of OOP standards
    			echo 'good' . PHP_EOL;
    			  $this -> _fetch();
    			  return isset($this -> _mapping[$this -> _position]);
    		  } else {
    			echo 'bad' . PHP_EOL;
    			  return false;
    		  }
    	   }

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: What was the purpose of this design?

    If you want to refer to a member, then yes, you want to use $this. If you want to reference the class, then use self.

    Not sure why the PHP council did it that way. You'll just have to ask them that.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jan 2009
    Posts
    1,689

    Re: What was the purpose of this design?

    No, I mean, why is it possible for $this to be not of type self, or any inherited class of thereof?

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: What was the purpose of this design?

    Which is why I suggested you ask PHP.

    http://bugs.php.net/report.php
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured