Comments (7)
Tristan: Thank you for these. I am hoping we can utilize XRegExp to ensure we can get all of the benefits of PHP's own flavor of regex (richer than JS') before we approve any version of these functions. Feel free to add them on any of the relevant site pages though or the wiki.
from locutus.
Hey guys, what should we do with this?
from locutus.
Regarding all regular expression function's, where (almost) full port is possible, we could indeed try to use XRegExp (or even write own regex engine that is identical to PHP's).
There is one big problem with functions like preg_match and preg_match_all. Both define an "out" param for matched strings and we can't mimic the behavior in JavaScript. The params are kind of crutial to the usability of the functions, thus this problem both IMO should be marked as "not porting".
At some point, I might take a closer look at the regex topic. There are more topics in phpjs that are pain in the ass. For example arrays. So far I haven't touched any array function, because many of the functions can't work properly on objects, because we can't neither assume nor control key order in an object. But this is a topic for separate discussion.
from locutus.
Ok let's leave it for now. About the arrays, we set out to port all functions and see how far we could go. I think it's ok to admit that there are limits to what we can reasonably be expected to do and document that order may not be preserved depending on platforms, vs hacking up our own datatypes or something.
from locutus.
Not sure if you were aware of this, Kevin, but the iteration order problem is not limited to reusing deleting properties in IE--it has been happening in Chrome (and not sure whether I may have seen this in FF too): https://code.google.com/p/v8/issues/detail?id=164 . That is why I started all that work in array() to allow, with configuration, the style:
array({key1: value1}, {key2: value2});
...for something looking more like associative arrays but can retain iteration order, e.g., when the functions aware of this structure are called on it (and this structure also supports more JavaScript-friendly jQuery-style chaining syntax).
It is, imo, not just a hack but a practical workaround, even if it would be easier (and less of a source of confusion) than had iteration order been made reliable across platform by the browsers.
I also think it is something we can educate users about if we provide them a working alternative rather than the pretension that the existing way is going to work. I did add notes to this effect in at least some of the array functions as I recall, but I also did not finish the work on allowing arrays to support the alternative syntax (so not all are ready even if you wanted to support this way).
Anyways, that's just my two cents, but if you want to remove support for the alternative syntax, I'd suggest moving all array functions (or those that rely on iteration order) into the experimental section. We might get some commotion from that, but perhaps that would be good if people are using them thinking they are working cross-platform.
from locutus.
Continuing array discussion in #148. Closing this issue as it's been decided we are not porting the remaining preg functions
from locutus.
unless someone uses XRegExp or the like to make it PHP-equivalent, right?
from locutus.
Related Issues (20)
- bin2hex() fails with unicode characters like Æ Ø Å æ ø å
- "contributing guidelines coding standards" url broken HOT 2
- [php/array/array_intersect.js] Simpler option HOT 3
- float bug and missing Q code HOT 2
- Linting upgrade HOT 1
- Failure to recognize some format and extract values in sscanf HOT 2
- [c/stdio/sprintf] %% consumes an extra arg HOT 5
- Question: Is strtotime Algorithmically Equivalent to the PHP Version? HOT 2
- hex2bin() Never Returns If More Than 1 Million Chars HOT 3
- Percentage for "similar_text" HOT 2
- Trying to get in touch regarding a security issue HOT 3
- strip_tags has some differences with php's version HOT 1
- Invalid syntax '/php/_helpers/_bc' in released '_locutus_shared/_locutus_shared_bc.js' HOT 2
- TypeError: Cannot read property '$locutus' of undefined HOT 1
- BUG : php function unserialize not working HOT 6
- php similar_text performance HOT 4
- Invalid serialization for floating numbers HOT 1
- Help - How install with Ionic? HOT 1
- bcmul is not working with decimal HOT 2
- fmod: toFixed() digits argument must be between 0 and 100
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from locutus.