u/Reasonable-Pass9841

▲ 1 r/PHP

Should spl_object_hash() be deprecated?

spl_object_id() is faster and more memory efficient for object identity checks.

Is there still any real advantage to spl_object_hash() today, or is it mostly legacy compatibility?

reddit.com
u/Reasonable-Pass9841 — 1 day ago
▲ 15 r/PHP

Building a JSONPath PHP Extension — Useful?

I’m thinking about building a PHP c extension for JSONPath querying, inspired by zig-jsonpath.

Example:

<?php

/*
|--------------------------------------------------------------------------
| JSONPath examples
|--------------------------------------------------------------------------
|
| JSONPath allows querying nested JSON values using expressions.
| Similar to XPath but for JSON.
|
*/

$json = '{
    "store": {
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 12.99
            },
            {
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99
            }
        ],
        "bicycle": {
            "color": "red",
            "price": 19.95
        }
    }
}';


/*
|--------------------------------------------------------------------------
| Get all authors
|--------------------------------------------------------------------------
*/

jsonpath_get($json, '$.store.book[*].author');

/*
Result:

[
    "Nigel Rees",
    "Evelyn Waugh",
    "Herman Melville"
]
*/


/*
|--------------------------------------------------------------------------
| Get first book title
|--------------------------------------------------------------------------
*/

jsonpath_get($json, '$.store.book[0].title');

/*
Result:

"Sayings of the Century"
*/


/*
|--------------------------------------------------------------------------
| Recursive search
|--------------------------------------------------------------------------
*/

jsonpath_get($json, '$..price');

/*
Result:

[
    8.95,
    12.99,
    8.99,
    19.95
]
*/


/*
|--------------------------------------------------------------------------
| Filter books cheaper than 10
|--------------------------------------------------------------------------
*/

jsonpath_get($json, '$.store.book[?(@.price < 10)]');

/*
Result:

[
    {
        "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
    },
    {
        "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99
    }
]
*/


/*
|--------------------------------------------------------------------------
| Books with ISBN
|--------------------------------------------------------------------------
*/

jsonpath_get($json, '$.store.book[?(@.isbn)]');

/*
Result:

[
    {
        "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99
    }
]
*/


/*
|--------------------------------------------------------------------------
| Get all objects in store
|--------------------------------------------------------------------------
*/

jsonpath_get($json, '$.store.*');

/*
Result:

[
    [...books...],
    {
        "color": "red",
        "price": 19.95
    }
]
*/


/*
|--------------------------------------------------------------------------
| Array slice
|--------------------------------------------------------------------------
*/

jsonpath_get($json, '$.store.book[:2]');

/*
Result:

First 2 books
*/


/*
|--------------------------------------------------------------------------
| Last book
|--------------------------------------------------------------------------
*/

jsonpath_get($json, '$.store.book[-1]');

/*
Result:

{
    "category": "fiction",
    "author": "Herman Melville",
    "title": "Moby Dick",
    "isbn": "0-553-21311-3",
    "price": 8.99
}
*/


/*
|--------------------------------------------------------------------------
| Wildcard everything
|--------------------------------------------------------------------------
*/

jsonpath_get($json, '$..*');

/*
Result:

Returns all values recursively
*/

Goals:

  1. Faster than pure PHP

  2. Low memory usage

  3. wildcard/filter support

  4. Maybe query raw JSON without full decoding

Would this be useful for:

1.WordPress

  1. Laravel

  2. API projects

Would love opinions before I start building

reddit.com
u/Reasonable-Pass9841 — 5 days ago

I’m considering building a PHP C extension that reimplements the WordPress hooks system in C. The goal is to reduce overhead from PHP-level execution, potentially achieving ~5x performance improvements and ~2x lower memory usage.

Has anyone explored something similar? What challenges should I expect in terms of compatibility with existing plugins/themes and WordPress internals?

reddit.com
u/Reasonable-Pass9841 — 18 days ago
▲ 5 r/PHP

Has anyone here implemented face recognition using PHP only? I’m exploring "mailmug/php-dlib", but not sure how practical it is. Any suggestions or experiences?

reddit.com
u/Reasonable-Pass9841 — 19 days ago