How to add a property to a PHP class?

Viewed 28
$action = $_POST['action']; 
switch($action)
{
case 0:
    $ss_echo = new StdClass();
    $ss_echo->action = $action + 100; //this returns null?
    $ss_echo->success = 0; //this returns 0
    
    echo(json_encode($ss_echo));
break;
}

What am I doing wrong that is making $action + 100 null when echoed?

EDIT (SOLVED):

$ss_echo = new StdClass();
$ss_echo->action = intval($action) + 100;
1 Answers

For sake of simplicity you can use associative array instead of new StdClass()

Related