Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 518
  • Last Modified:

PHP 4.4.7 class variables

I have created a simple class in PHP 4.4.7, The class has a few variables and is reading a URL using cURL.
For some reason any update to one variable effected all variables.
Displaying the value of err or err1 includes the file content.
"err len=19587,err1 len=19587, File Src len = 19587"
Is there something I am missing or is it a bug ?
class grc_form2mail {
	
	var $url='';
	var $err='';
	var $err1='';
	var $fileSrc='';
	function addErr($errMsg)
	{
		$this->$err.=htmlspecialchars($errMsg) . "<br>\n";
	}
	function displayErrors()
	{
		print($this->$err . "<br>\n");
	}
	function err1()
	{
		print($this->$err1);
	}
	function readSrc($pURL)
	{
		$this->$url=$pURL;
		$this->$fileSrc='';
		$this->$err='';
		if ($pURL=='')
			return;
		// open session with url
		$ch=curl_init();
        //return the transfer as a string 
		curl_setopt($ch, CURLOPT_URL, $pURL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
		curl_setopt($ch, CURLOPT_USERAGENT, USERAGENT);
        // $output contains the output string 
		$this->$err1.='err len=' . strlen($this->$err) . ',err1 len=' . strlen($this->$err) . ', File Src len = ' . strlen($this->$fileSrc) . " <br>\n";
        $this->$fileSrc.=curl_exec($ch);
		$this->$err1.='err len=' . strlen($this->$err) . ',err1 len=' . strlen($this->$err) . ', File Src len = ' . strlen($this->$fileSrc) . " <br>\n";
        // close curl resource to free up system resources 
        curl_close($ch);      
	}
..

Open in new window

0
ggivati
Asked:
ggivati
1 Solution
 
VanHackmanCommented:

Try the following code... ;)
class grc_form2mail {
        
        var $url='';
        var $err='';
        var $err1='';
        var $fileSrc='';

        function addErr($errMsg)
        {
                $this->err.=htmlspecialchars($errMsg) . "<br>\n";
        }
        function displayErrors()
        {
                print($this->err . "<br>\n");
        }
        function err1()
        {
                print($this->err1);
        }
        function readSrc($pURL)
        {
                $this->url=$pURL;
                $this->fileSrc='';
                $this->err='';
                if ($pURL=='')
                        return;
                // open session with url
                $ch=curl_init();
        //return the transfer as a string 
                curl_setopt($ch, CURLOPT_URL, $pURL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
                curl_setopt($ch, CURLOPT_USERAGENT, USERAGENT);
        // $output contains the output string 
                $this->err1.='err len=' . strlen($this->err) . ',err1 len=' . strlen($this->err) . ', File Src len = ' . strlen($this->fileSrc) . " <br>\n";
        $this->fileSrc.=curl_exec($ch);
                $this->err1.='err len=' . strlen($this->err) . ',err1 len=' . strlen($this->err) . ', File Src len = ' . strlen($this->fileSrc) . " <br>\n";
        // close curl resource to free up system resources 
        curl_close($ch);      
        }

Open in new window

0
 
Ray PaseurCommented:
"class in PHP 4.4.7"

That PHP version may be the most central problem here!  PHP 4 is not supported any more, and you really need to find your way to PHP5.  For the most part, the OOP support in PHP 5 is more real-world, with class constructors, correct inheritance, etc.

But that said, it looks like your vars are      
  var $url='';
  var $err='';
  var $err1='';
  var $fileSrc='';

The readSrc() method changes the values of all of these.  As a debugging step, you might consider using var_dump() to print out the value of the internal variables at different points in the execution of the program code.  Then you can easily see what the logic is doing to your variable values.

Best regards, ~Ray
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now