object.phpt 918 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. --TEST--
  2. Test V8::executeString() : Object passed from PHP
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. $JS = <<< EOT
  8. function dump(a)
  9. {
  10. for (var i in a) {
  11. var val = a[i];
  12. print(i + ' => ' + val + "\\n");
  13. }
  14. }
  15. function test()
  16. {
  17. dump(PHP.myobj);
  18. PHP.myobj.foo = 'CHANGED';
  19. PHP.myobj.mytest();
  20. }
  21. test();
  22. print(PHP.myobj.foo + "\\n");
  23. EOT;
  24. // Test class
  25. class Testing
  26. {
  27. public $foo = 'ORIGINAL';
  28. private $my_private = 'arf'; // Should not show in JS side
  29. protected $my_protected = 'argh'; // Should not show in JS side
  30. function mytest() { echo 'Here be monsters..', "\n"; }
  31. }
  32. $a = new V8Js();
  33. $a->myobj = new Testing();
  34. $a->executeString($JS, "test.js");
  35. // Check that variable has not been modified
  36. var_dump($a->myobj->foo);
  37. ?>
  38. ===EOF===
  39. --EXPECT--
  40. mytest => function () { [native code] }
  41. $foo => ORIGINAL
  42. Here be monsters..
  43. CHANGED
  44. string(7) "CHANGED"
  45. ===EOF===