Page 1 of 1

Undefined.... var

Posted: Tue Aug 29, 2006 6:56 pm
by ol4pr0
Ok what am i doing wrong.. i just cant see it.

Code: Select all

class (foo)  {
	var $transGroup = "xx"; 
	var $orderParty = "xxxxxxx"; # Set account nummer van Wadloop
	var $hasNameCode = false; # Kan true zijn maar deze is false default.
	var $nameOrderingParty = "xxxxx"; # True wanneer NameOrderingParty word gebruikt.
	var $pattern = "dd-mm-yyyy";

	function xmlHeader() {

		$_xml ="<clieop transactionGroup=".$this->transGroup.">\r\n"; 
		$_xml .="<batch>\r\n"; 
		$_xml .="<accountNumberOrderingParty value=".$orderParty."/>\r\n"; 		
		$_xml .="<hasNameCode value=".$this->hasNameCode."/>\r\n";
         }      
}
Error ..

Notice: Undefined property: transGroup
aswell as for the others..

Posted: Tue Aug 29, 2006 6:58 pm
by feyd
That's the exact code? .. all of it?

Posted: Tue Aug 29, 2006 6:58 pm
by RobertGonzalez
Try this...

Code: Select all

<?php
class foo  {
        var $transGroup = 'xx';
        var $orderParty = 'xxxxxxx'; # Set account nummer van Wadloop
        var $hasNameCode = false; # Kan true zijn maar deze is false default.
        var $nameOrderingParty = 'xxxxx'; # True wanneer NameOrderingParty word gebruikt.
        var $pattern = 'dd-mm-yyyy';

        function xmlHeader() {

                $_xml ="<clieop transactionGroup=".$this->transGroup.">\r\n";
                $_xml .="<batch>\r\n";
                $_xml .="<accountNumberOrderingParty value=".$this->orderParty."/>\r\n";           
                $_xml .="<hasNameCode value=".$this->hasNameCode."/>\r\n";
         }     
}
?>
Also, make sure that none of the values for the vars are variable. They must be static in order to not error/notice out.

Posted: Tue Aug 29, 2006 7:05 pm
by ol4pr0
Yea basicly.. ofcourse it has some more at the bottom and all that.

but even like that it doesnt work.. i tried it before asking it jeje..

Posted: Tue Aug 29, 2006 7:09 pm
by ol4pr0
to show. you

Errors
Notice: Undefined variable: this in C:\Apache\Apache2\htdocs\xmlfoo.php on line 11

Notice: Undefined variable: this in C:\Apache\Apache2\htdocs\xmlfoo.php on line 13

Notice: Undefined variable: this in C:\Apache\Apache2\htdocs\xmlfoo.php on line 14

Code: Select all

<?php 
class foo  { 
        var $transGroup = 'xx'; 
        var $orderParty = 'xxxxxxx'; # Set account nummer van Wadloop 
        var $hasNameCode = false; # Kan true zijn maar deze is false default. 
        var $nameOrderingParty = 'xxxxx'; # True wanneer NameOrderingParty word gebruikt. 
        var $pattern = 'dd-mm-yyyy'; 

        function xmlHeader() { 

                $_xml ="<clieop transactionGroup=".$this->transGroup.">\r\n"; 
                $_xml .="<batch>\r\n"; 
                $_xml .="<accountNumberOrderingParty value=".$this->orderParty."/>\r\n";            
                $_xml .="<hasNameCode value=".$this->hasNameCode."/>\r\n"; 
                $_xml .="</batch>\r\n"; 
				$_xml ="</clieop>\r\n"; 


         }      
} 


echo foo::xmlHeader();
?>

Posted: Tue Aug 29, 2006 7:11 pm
by feyd
You're calling the function statically, $this doesn't exist under that condition. self::$varname will however.

Posted: Tue Aug 29, 2006 7:12 pm
by RobertGonzalez
Try returning something from the function...

Code: Select all

<?php
class foo  {
        var $transGroup = 'xx';
        var $orderParty = 'xxxxxxx'; # Set account nummer van Wadloop
        var $hasNameCode = false; # Kan true zijn maar deze is false default.
        var $nameOrderingParty = 'xxxxx'; # True wanneer NameOrderingParty word gebruikt.
        var $pattern = 'dd-mm-yyyy';

        function foo() {}

        function xmlHeader() {
                $_xml ="<clieop transactionGroup=".$this->transGroup.">\r\n";
                $_xml .="<batch>\r\n";
                $_xml .="<accountNumberOrderingParty value=".$this->orderParty."/>\r\n";           
                $_xml .="<hasNameCode value=".$this->hasNameCode."/>\r\n";
                $_xml .="</batch>\r\n";
                $_xml ="</clieop>\r\n";
                
                return $_xml;
         }     
}

$foo = new foo();
echo $foo->xmlHeader();
echo 'transGroup is ' . $foo->transGroup;
?>