You are here: PHP 5 Re-assign $this PROBLEM - any ideas? « PHP Programming Language « IT news, forums, messages
PHP 5 Re-assign $this PROBLEM - any ideas?

Posted by Ryan White on 02/16/06 09:33

Hi all
Just a quickie, in case it's been covered, like a million times or
something.

I'm self taught, and thought I was being pretty clever when building a
"messaging" class.

The idea was to abstract "html email", "text email" and "sms message" up a
layer into a "message"

To get a message started, I call on something like this:

$msg = new Message("sms");

Message (which re-assigns the $this variable) then looks something like
this:

class Message{
var $message_hash;
var $message_path;//this can be changed, in case stuff is moved in future...
function ryan_Message($type=""){//starts the whole thing
switch($type){
case "html"://this means an html email
include_once("HtmlMessage.php");
$this = new HtmlMessage();
break;
case "text"://this means a text mail
include_once("TextMessage.php");
$this = new TextMessage();
break;
case "sms"://this means an sms message
include_once("SmsMessage.php");
$this = new SmsMessage();
break;
}// end switch
}// end function
}// end class

Each class has methods that are named the same, but act a little
differently, so, basically, I can use the same set of commands to compose a
message and send it, regardless of what type of message it is.

Things work fantastically under php4, but I know that when I swap over to
php5, it's going to throw a hissy fit, because reassigning $this is not
allowed.

Aside from going around the Message class, and just starting messages of a
particular type from scratch:

Is there some sort of cunning retro-fit I could do to the Message class, so
I don't have to trawl through thousands of lines of code?

Any help much appreciated
Thanks
Ryan

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация