TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   TalkPHP Developer Team (http://www.talkphp.com/talkphp-developer-team/)
-   -   print_r noting happen with my class (http://www.talkphp.com/talkphp-developer-team/6080-print_r-noting-happen-my-class.html)

rawprogrammer 01-06-2012 03:21 AM

print_r noting happen with my class
 
i build new class to loop field html but when i print_r it nothing "FeildHTML Object ( )"
here my code

class FeildHTML
{
public function setFeildCheck ($field,$fieldval,$unsetbutton)
{
$field = array($field);
$fieldval = array($fieldval);
$label = array_combine($field,$fieldval);
unset($_POST [$unsetbutton]);
foreach($_POST as $k=>$v)
{
$$key = $v;
echo $label[$k]."=$v<br />";
}
}

}
$a = new FeildHTML();
$a->setFeildCheck('a','b','c');
print_r($a);
?>

tony 01-09-2012 04:36 PM

What were you expecting it would show? print_r would only show the properties in an object in this case. which the class doesn't, have a field. try adding a property and you would see the value print with print_r. like this:

PHP Code:
<?php
class FeildHTML
{
  public $state = 'not set'; //I added this property

  public function setFeildCheck ($field,$fieldval,$unsetbutton)
  {
    $field = array($field);
    $fieldval = array($fieldval);
    $label = array_combine($field,$fieldval);
    unset($_POST [$unsetbutton]);
    foreach($_POST as $k=>$v)
    {
      $$key = $v;
      echo $label[$k]."=$v<br />";
    }

    $this->state = 'set';
  }
}

$a = new FeildHTML();
$a->setFeildCheck('a','b','c');
print_r($a);
?>
//print_r output is this:
FeildHTML Object
(
    [state] => set
)


All times are GMT. The time now is 07:06 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0