PHP4 Class Functionality

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

PHP4 Class Functionality

Post 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]
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post 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, ;)
Last edited by hongco on Thu Mar 17, 2005 1:35 pm, edited 1 time in total.
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

__set is a valid function name for php4, so you could technically just call the function.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
Post Reply