bgsomers Posted January 29, 2007 Share Posted January 29, 2007 In the following routine, $example->items leads to the value "g-items" as expected.But why does $this->items lead to nothing?Is there some way in PHP, to display the contents of a non-printable variable in octal or hexadecimal form?Bruce[code]<?phpclass Cart { var $items = "g-item"; // Items in our shopping cart // Add $num articles of $artnr to the cart function add_item($artnr, $num) { $this->items[$artnr] += $num; } // Take $num articles of $artnr out of the cart function remove_item($artnr, $num) { if ($this->items[$artnr] > $num) { $this->items[$artnr] -= $num; return true; } elseif ($this->items[$artnr] == $num) { unset($this->items[$artnr]); return true; } else { return false; } }}$example = new Cart();echo '$example->items yields: '.$example->items.'<br/>';echo '$this->items yields nothing: '.$this->items.'<br/>';echo '$items yields nothing: '.$items.'<br/>';print_r($example);?> [/code] Link to comment https://forums.phpfreaks.com/topic/36168-examining-variables/ Share on other sites More sharing options...
trq Posted January 29, 2007 Share Posted January 29, 2007 Because $this is only relevent when used within a class. Link to comment https://forums.phpfreaks.com/topic/36168-examining-variables/#findComment-171741 Share on other sites More sharing options...
bgsomers Posted January 29, 2007 Author Share Posted January 29, 2007 Thank you.Then $this->xxxx is applicable only within the definition of a class, to refer to a variable xxxx defined therein?Outside of such a class definition, the name of an object in which the variable is defined is (always) needed? Link to comment https://forums.phpfreaks.com/topic/36168-examining-variables/#findComment-171879 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.