Giter VIP home page Giter VIP logo

Comments (7)

brettz9 avatar brettz9 commented on May 21, 2024

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.

kvz avatar kvz commented on May 21, 2024

Hey guys, what should we do with this?

from locutus.

kukawski avatar kukawski commented on May 21, 2024

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.

kvz avatar kvz commented on May 21, 2024

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.

brettz9 avatar brettz9 commented on May 21, 2024

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.

kvz avatar kvz commented on May 21, 2024

Continuing array discussion in #148. Closing this issue as it's been decided we are not porting the remaining preg functions

from locutus.

brettz9 avatar brettz9 commented on May 21, 2024

unless someone uses XRegExp or the like to make it PHP-equivalent, right?

from locutus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.