Jump to content

$this->ipsclass not avaliable to constructor


Guest marcele

Recommended Posts

In my previous post where I gave an example of a better way to pass around the $ipsclass object ..you said..
"I'll likely do that when PHP 5 is used more than PHP 4." .. The example I gave was based on php5 however you can do the same thing via php4..This way you have access to the $ipsclass object in any constructors. Just trying to help out ;)

 $ipsclass->sess = new session($ipsclass);


 class session{


var $ipsclass;

var $ip_address;


function session(&$ipsclass) {


	 $this->ipsclass = &$ipsclass;

	 $this->ip_address = $this->ipsclass->parse_clean_value($_SERVER['REMOTE_ADDR']);


 }

Link to comment
Share on other sites

  • Management

I'd rather pass by reference implicitly than by constructor.

There are few if any occasions where passing ipsclass into the constructor is required. The ipsclass.php "initiate_ipsclass" is there not only for the ipsclass, but also because the settings aren't available until the DB is connected and queried, and some of the DB connection code is in ipsclass.php.

The only real time not being able to pass through to the constructor has caused a work around is class_email.php.

As calltime references are being depreciated in PHP 5, I figured I'd not rely on them as a method of passing ipsclass around.

Link to comment
Share on other sites

Ascalltimereferencesare being depreciated in PHP 5, I figured I'd not rely on them as amethod of passing ipsclass around.



This isn't a calltime reference.. The reference is handled implicitly by the constructor declaration which is the desired method in php5. Here is an example:

BAD DON'T USE

 $ipsclass->sess = new session(&$ipsclass);

GOOD USE

 $ipsclass->sess = new session($ipsclass);

The class constructor should decide if the object should be a reference or not ... Not the logic of the page controller :P

 class session{


var $ipsclass;

var $ip_address;


function session(&$ipsclass) {


	 $this->ipsclass = &$ipsclass;

	 $this->ip_address = $this->ipsclass->parse_clean_value($_SERVER['REMOTE_ADDR']);


 }

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...