Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Lost for how to include #48

Open
theDanielJLewis opened this issue Dec 7, 2019 · 2 comments
Open

Lost for how to include #48

theDanielJLewis opened this issue Dec 7, 2019 · 2 comments

Comments

@theDanielJLewis
Copy link

Please treat me like I know almost nothing about Composer.

How do I actually get JSONPath into my project? After running composer require flow/jsonpath dev-master or composer require flow/jsonpath, my PHP looks essentially like this:

<?php
require (__DIR__ . '/vendor/autoload.php');

$data = ['people' => [['name' => 'Joe'], ['name' => 'Jane'], ['name' => 'John']]];
$result = (new JSONPath($data))->find('$.people.*.name'); // returns new JSONPath

But I get the error "Class 'JSONPath' not found."

I'm doing something wrong, but I don't know what.

@stephenfrank
Copy link
Contributor

Hi Daniel,

You need to include the use statement at the top of your file so that PHP knows which namespace to use when looking for the class.

<?php
use Flow\JSONPath\JSONPath;
require (__DIR__ . '/vendor/autoload.php');

you can also use a fully qualified namespace + class name eg:
$result = (new \Flow\JSONPath\JSONPath($data))->find('$.people.*.name');

Composer packages and PHP 5.3+ code uses namespaces to avoid naming conflicts in class names and is a good thing to get familiar with:
https://www.php.net/manual/en/language.namespaces.rationale.php

Hope that helps!

@martinssipenko
Copy link
Contributor

This project is now marked as abandoned and suggests using softcreatr/jsonpath as a replacement. If you think this issue is still relevant please open a new ticket under the new project.

https://github.com/SoftCreatR/JSONPath

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants