php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58983 Assigning JS anonymous functions to PHP object properties
Submitted: 2009-12-09 17:55 UTC Modified: 2017-01-10 08:01 UTC
Votes:2
Avg. Score:2.0 ± 1.0
Reproduced:0 of 0 (0.0%)
From: ionut dot g dot stan at gmail dot com Assigned:
Status: Suspended Package: spidermonkey (PECL)
PHP Version: 5.3.0 OS: Ubuntu 9.10
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-12-09 17:55 UTC] ionut dot g dot stan at gmail dot com
Description:
------------
I'm not sure how to describe this bug (feature request) better than the code below.

Anyway, thanks for your work. What you've done is great!

Reproduce code:
---------------
<?php

$js     = new JSContext;
$window = new StdClass;

$js->assign('window', $window);

$script = <<<JS
    window.onload = function () {
        return 'foobar';
    };

    window.onload();
JS;

var_dump($js->evaluateScript($script));
var_dump($window->onload instanceof Closure);


Expected result:
----------------
string 'foobar' (length=6)

boolean true


Actual result:
--------------
Exception: TypeError: window.onload is not a function in... for the first var_dump()

and

false for the second var_dump().

The onload property is actually an instance of StdClass, which isn't necessarily false for JavaScript, as functions are objects. Unfortunately StdClass isn't callable in PHP.

Having onload being an instance of Closure would be much better.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-10 08:01 UTC] kalle@php.net
-Status: Open +Status: Suspended
 [2017-01-10 08:01 UTC] kalle@php.net
Suspending this report as the extension have not had a release for almost 5 years.  Please revive this if the extension once again shows life
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 06:01:30 2024 UTC