Page 1 of 1

PHP4 Class Functionality

Posted: Thu Mar 17, 2005 1:07 pm
by jwalsh
Hi,

Wrote a simple class for a PHP5 server, but now someone wants to buy the script for use on php4. I've gotten everything working, except this.

Code: Select all

// Set Attribute Function
    Function __set($name, $value) {
      // Check if password submitted, and md5 it
      if ($name == "Password") {
        $value = md5($value);
      }
      
      $this->$name = $value;
    }
I know __set and __get are php5 only, but how would you achieve something similar in PHP4, I'd assume to write another function to take the place of this, and call it rather than implicitly run it like I did in 5?

Thanks,

Josh


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Thu Mar 17, 2005 1:32 pm
by hongco

Code: Select all

$this->$name = $value;
on my class if I had $ for the "name", it would create error on php 4+
so, maybe you could try with:

Code: Select all

$this->name = $value;
PS. as soon as i am done with my current project, I need to get a book for 5.0, ;)

Posted: Thu Mar 17, 2005 1:34 pm
by jwalsh
Perhaps I'm wrong... But I didn't think __set was valid at all in PHP4? Just like __construct isn't valid. Am I wrong here?

Josh

Posted: Thu Mar 17, 2005 2:15 pm
by feyd
__set is a valid function name for php4, so you could technically just call the function.

Posted: Thu Mar 17, 2005 3:45 pm
by Ambush Commander
Err... if you don't have the magic functionality associated with __set and __get, then you're going to have to create alternative paths for it: I don't see why you need this code.