Jump to content

Examining variables


bgsomers

Recommended Posts

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]<?php
class 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

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.