0

I need to do something like:

$object = (typeof($object))$value;

Knowing that both $object and $value are scalar types.

Bige Young
  • 25
  • 5
  • this is not possible in PHP see https://stackoverflow.com/questions/2226103/how-to-cast-objects-in-php you need to write our own casting function – jDolba Jan 22 '19 at 03:53

1 Answers1

0
$copy = $value;
if(settype($copy, gettype($object)))
    $object = $copy;
shingo
  • 18,436
  • 5
  • 23
  • 42