Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8272805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:15:14+00:00 2026-06-08T07:15:14+00:00

Because I prefer a more object oriented approach I wrote my own json class

  • 0

Because I prefer a more object oriented approach I wrote my own json class to handle also json_last_error for decode and encode.

Somehow I get a php warning for the depth property of the json_decode method.

The PHP core api (eclipse PDT) for the json_decode method looks like the following:

function json_decode ($json, $assoc = null, $depth = null) {}

So far so good but if I write my own class like this:

function my_json_decode ($json, $assoc = null, $depth = null) {
    return json_decode($json, $assoc, $depth);
}

and try to run it as follow:

$json = '{ "sample" : "json" }';
var_dump( my_json_decode($json) );

I get the following warning:

Warning: json_decode(): Depth must be greater than zero in /

Did I miss anything? I thought if I pass null for a property to a method which set the property itself to null it should be fine?!

Using: Server: Apache/2.2.22 (Unix) PHP/5.3.10

Thanks for the help!


[Edit] to clarify where my leak of understanding was:

I am using Eclipse Indigo + PDT. The PDT PHP core api of org.eclipse.php.core.language is different from what php.net say about json_decode:

json_decode org.eclipse.php.core.language:

json_decode ($json, $assoc = null, $depth = null)

json_decode php.net:

json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:15:16+00:00Added an answer on June 8, 2026 at 7:15 am

    Depth is the recursion depth (should be an INTEGER) of json_decode. See the manual for more details.

    What you are doing is that you are setting $depth to 0. Since your json object’s depth is 2. the minimum value of $depth must be 2. Also your code would work fine with any value of depth>2, but I would recommend to use the default value of 512 (it was 128 initially which was later increased to 512 in PHP 5.3.0)

    Also do note that assoc has to be a bool value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Usually I prefer to write my own solutions for trivial problems because generally plugins
Though it's debatable, I've heard the majority of CSS developers prefer multi-line because of
Because I've overloaded the operator++ for an iterator class template<typename T> typename list<T>::iterator& list<T>::iterator::operator++()
Possible Duplicate: Does Java guarantee that Object.getClass() == Object.getClass()? If I have a class
I would like to write an object generator for a templated RAII class --
x = ['Some strings.', 1, 2, 3, 'More strings!', 'Fanc\xc3\xbf string!'] y = [i.decode('UTF-8')
When implementing a needle search of a haystack in an object-oriented way, you essentially
Let's say I have the following class class Parent(object): Options = { 'option1': 'value1',
Because shells other than ksh do not support pass-by-reference, how can multiple arrays be
Because data from file look like this: line 1 is name (first last), next

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.