UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

402 lines (306 loc) 12.7 kB
<!-- Generated by Rakefile:build --> <strong> <a href="http://opitmami.ru/" rel="nofollow">henryfikse</a> </strong> on 2011-12-26 18:24:18 <br /> <hr /> <strong> <a href="http://googdi57.tk/" rel="nofollow">mashikseli</a> </strong> on 2011-12-17 11:40:45 <br /> <hr /> <strong> gunsilie </strong> on 2011-12-16 14:12:43 <br /> <hr /> <strong> mashikseli </strong> on 2011-12-15 08:57:44 <br /> <hr /> <strong> <a href="http://unin62.tk/" rel="nofollow">ganiselim</a> </strong> on 2011-12-14 08:24:54 <br /> <hr /> <strong> <a href="http://kethough51.tk/" rel="nofollow">sametikaresi</a> </strong> on 2011-12-14 02:44:13 <br /> <hr /> <strong> ganiselim </strong> on 2011-12-13 14:52:25 <br /> <hr /> <strong> <a href="http://orskyl26.tk/" rel="nofollow">Toilbonsill</a> </strong> on 2011-12-08 15:15:45 <br /> <hr /> <strong> Toilbonsill </strong> on 2011-12-08 01:21:48 <br /> <hr /> <strong> ZL@B </strong> on 2011-10-10 01:43:17 <br /> <hr /> <strong> glymninitty2005 </strong> on 2011-08-10 00:30:07 <br /> <hr /> <strong> Rhiccadssaria1995 </strong> on 2011-08-09 03:39:56 <br /> <hr /> <strong> Ralkekaltep1976 </strong> on 2011-08-07 23:22:49 <br /> <hr /> <strong> Bemjuple2008 </strong> on 2011-08-04 07:53:40 <br /> <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2009-02-11 02:21:13 <br /> @ Brett Zamir: Yeah sounds good! I will need to do some work on the tester soon. But first the phpjs.org site! The online compiler is coming along nicely have you seen it? <hr /> <strong> <a href="http://bahai-library.com" rel="nofollow">Brett Zamir</a> </strong> on 2009-02-06 17:32:31 <br /> I don't know about the errors with Rhino, but maybe that is due to going through window properties? I concur with your steps of waiting to build a module, and might suggest also waiting for all arguments to be implemented (unless impossible) for any completed functions. Is it ok for me to move interface_exists() and get_declared_interfaces() (and to add class_implements()) to not porting? JavaScript has no built-in interfaces, so we could not implement these without adding our own language constructs to JavaScript. <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2009-02-01 22:55:04 <br /> @ Brett Zamir: They keep giving me <pre><code> Exception in thread &amp;quot;Thread-0&amp;quot; org.mozilla.javascript.EcmaError: TypeError: Cannot read property &amp;quot;prototype&amp;quot; from undefined </code></pre> ..errors, even when I check for prototype first. Rhino issue maybe. Concidering the functions that are in unported/notporting, etc. That has never been a scientific process. It was the result of a sleepless night of crawling php.net. It has never been more than a rough guideline and has always been open to suggestions. Bringing me to SPL. I think that may be taking it to another level. That can be a good or a bad thing, but I think for now we should focus on the normal functions &amp;amp; the site of the project. But that's my humble opinion, I'm open to ideas. btw I think we should move deprecated functions to _notporting, so that's what I did for now. As far as the Mozilla thing goes. I have actually never made an extension or anything but Yeah it would be cool if we're included at some point. I don't know if they're interested or anything, but no harm in asking, right? I do think we should further professionalize PHP.JS before taking such steps though. In my eyes mainly meaning: - bugfixing - porting more _unported - making everything associative-aware - move out the development process to phpjs.org - deciding on a good 'default' package that doesn't contain any controversial functions <hr /> <strong> <a href="http://bahai-library.com" rel="nofollow">Brett Zamir</a> </strong> on 2009-01-31 13:09:33 <br /> Sorry, also realized the new one I just submitted now for get_class_vars() should have variable names changed to reflect the behavior of this function: <pre><code> function get_class_vars (name) { var constructor, retArr={}; if (typeof name === 'function') { constructor = name; } else if (typeof name === 'string') { constructor = window[name]; } for (var prop in constructor) { if (typeof constructor[prop] !== 'function' &amp;amp;&amp;amp; prop !== 'prototype') { retArr[prop] = constructor[prop]; } } // Comment out this block to behave as &amp;quot;class&amp;quot; is usually defined in JavaScript convention for (var prop in constructor.prototype) { if (typeof constructor.prototype[prop] !== 'function') { retArr[prop] = constructor.prototype[prop]; } } return retArr; }</code></pre> <hr /> <strong> <a href="http://bahai-library.com" rel="nofollow">Brett Zamir</a> </strong> on 2009-01-31 13:06:40 <br /> Sorry, just realized that get_class_method() returns an associative array. Here it is again, along with get_class_vars() and get_object_vars(): <pre><code> function Myclass () {this.privMethod = function(){}} Myclass.classMethod = function () {} Myclass.prototype.myfunc1 = function () { return(true); }; Myclass.prototype.myfunc2 = function () { return(true); } whatIs(get_class_methods('Myclass')); var myClassObj = new Myclass(); whatIs(get_class_methods(myClassObj)); function get_class_methods (name) { var constructor, retArr={}; if (typeof name === 'function') { constructor = name; } else if (typeof name === 'string') { constructor = window[name]; } else if (typeof name === 'object') { constructor = name; for (var method in constructor.constructor) { // Get class methods of object's constructor if (typeof constructor.constructor[method] === 'function') { retArr[method] = constructor.constructor[method]; } } // return retArr; // Uncomment to behave as &amp;quot;class&amp;quot; is usually defined in JavaScript convention (and see comment below) } for (var method in constructor) { if (typeof constructor[method] === 'function') { retArr[method] = constructor[method]; } } // Comment out this block to behave as &amp;quot;class&amp;quot; is usually defined in JavaScript convention (and see comment above) for (var method in constructor.prototype) { if (typeof constructor.prototype[method] === 'function') { retArr[method] = constructor.prototype[method]; } } return retArr; }</code></pre> and: <pre><code> function Myclass () {this.liveProp = 'prop';} Myclass.classProp = 'classPropVal'; Myclass.prototype.myprop1 = 1; Myclass.prototype.myprop2 = 2; whatIs(get_class_vars('Myclass')); var myClassObj = new Myclass(); myClassObj.prototype = {a:'b'}; function get_class_vars (name) { var constructor, retArr={}; if (typeof name === 'function') { constructor = name; } else if (typeof name === 'string') { constructor = window[name]; } for (var method in constructor) { if (typeof constructor[method] !== 'function' &amp;amp;&amp;amp; method !== 'prototype') { retArr[method] = constructor[method]; } } // Comment out this block to behave as &amp;quot;class&amp;quot; is usually defined in JavaScript convention for (var method in constructor.prototype) { if (typeof constructor.prototype[method] !== 'function') { retArr[method] = constructor.prototype[method]; } } return retArr; } function get_object_vars (obj) { var retArr={}; for (var prop in obj) { if (typeof obj[prop] !== 'function' &amp;amp;&amp;amp; prop !== 'prototype') { retArr[prop] = obj[prop]; } } for (var prop in obj.prototype) { if (typeof obj.prototype[prop] !== 'function') { retArr[prop] = obj.prototype[prop]; } } return retArr; }</code></pre> <hr /> <strong> <a href="http://bahai-library.com" rel="nofollow">Brett Zamir</a> </strong> on 2009-01-31 11:44:54 <br /> Here's another.... get_class_method(). I've left comments on how to get only the &amp;quot;class methods&amp;quot; as typically used in JavaScript (as opposed to PHP) terminology (i.e., not privileged or prototype methods, but those in the class &amp;quot;namespace&amp;quot;). <pre><code>function Myclass () {this.privMethod = function(){}} Myclass.classMethod = function () {} Myclass.prototype.myfunc1 = function () { return(true); }; Myclass.prototype.myfunc2 = function () { return(true); } alert(get_class_methods('Myclass')); // classMethod,myfunc1,myfunc2 var myClassObj = new Myclass(); alert(get_class_methods(myClassObj)); function get_class_methods (name) { var constructor, retArr=[]; if (typeof name === 'function') { constructor = name; } else if (typeof name === 'string') { constructor = window[name]; } else if (typeof name === 'object') { constructor = name; for (var method in constructor.constructor) { // Get class methods of object's constructor if (typeof constructor.constructor[method] === 'function') { retArr.push(method); } } // return retArr; // Uncomment to behave as &amp;quot;class&amp;quot; is usually defined in JavaScript convention (and see comment below) } for (var method in constructor) { if (typeof constructor[method] === 'function') { retArr.push(method); } } // Comment out this block to behave as &amp;quot;class&amp;quot; is usually defined in JavaScript convention (and see comment above) for (var method in constructor.prototype) { if (typeof constructor.prototype[method] === 'function') { retArr.push(method); } } return retArr; }</code></pre> <hr /> <strong> <a href="http://bahai-library.com" rel="nofollow">Brett Zamir</a> </strong> on 2009-01-31 07:45:46 <br /> Also, for get_declared_interfaces() and interface_exists() (and class_implements() but you don't seem to have these in your imported list: http://cn.php.net/manual/en/ref.spl.php -- btw, is it easy to say which modules you included/excluded?), since JavaScript offers no formal way to implement interfaces, do you want to move these to not porting? We could implement our own interface system (which even checked the number of arguments, etc.) and which worked with these PHP-named functions, but I presume that is beyond your intended scope here (though it would be pretty cool to pseudo-standardize on an interface system for JavaScript, at least until JS 2.0). Off the topic, as far as the php_js global, in the namespaced version of PHP.JS, you could put that at the top of the (function())() closure namespacing, so it wasn't actually global. And another off-the-topic, https://wiki.mozilla.org/Labs/JS_Modules , they state there &amp;quot;If you would like to contribute a new module, get in touch with us at #labs!&amp;quot;, so at whatever point you think we have something, we can submit a PHP-JS module for Mozilla so a bunch of extensions (and the same extension) could be able to reuse the module without any additional loading cost! <hr /> <strong> <a href="http://bahai-library.com" rel="nofollow">Brett Zamir</a> </strong> on 2009-01-31 06:57:30 <br /> Hi Kevin, call_user_method() and call_user_method_array() are now deprecated in PHP in favor of call_user_function (with the array argument). Do you want to move to not porting, or use the following? <pre><code>function call_user_method(method, obj) { // http://kevin.vanzonneveld.net // + original by: Brett Zamir var func = eval(obj+&amp;quot;['&amp;quot;+method+&amp;quot;']&amp;quot;); if (typeof func != 'function') { throw new Exception(func + ' is not a valid method'); } return func.apply(null, Array.prototype.slice.call(arguments, 2)); } function call_user_method_array(method, obj, params) { // http://kevin.vanzonneveld.net // + original by: Brett Zamir var func = eval(obj+&amp;quot;['&amp;quot;+method+&amp;quot;']&amp;quot;); if (typeof func != 'function') { throw new Exception(func + ' is not a valid method'); } return func.apply(null, params); }</code></pre> <hr />