Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP include files are making JSON data invalid
    primarykey
    data
    text
    <p>I'm relatively new to php development but not to web development in general.</p> <p>I have the following php file:</p> <pre><code>&lt;?php class dialogResult{ var $Message; var $Title; var $Height; var $GenericData; function __construct(){ $this-&gt;Height = 10; } } header("Cache-Control: no-cache", true); header("Content-type: application/json; charset=utf-8", true); $dr = new dialogResult(); $dr-&gt;Message = "A Test Message encoded"; $dr-&gt;Height = 10; $dr-&gt;GenericData = "Empty"; $dr-&gt;Title = "My Message"; echo(json_encode($dr)); ?&gt; </code></pre> <p>This returns JSON data as expected, however if I move the class to a separate file and add an include, include_once, require, or require_once it returns invalid JSON data. Can anyone tell me why this would be?</p> <p>It doesn't have to be just moving this class, if I have ANY included file it makes the data invalid.</p> <p>Thanks,</p> <p>Keith</p> <p>Here is the include class, I've also tried removing the ?></p> <pre><code>&lt;?php class dialogResult{ var $Message; var $Title; var $Height; var $GenericData; function __construct(){ $this-&gt;Height = 10; } } </code></pre> <p>There are no leading or trailing spaces anywhere. Here is the 'invalid' JSON that is returned:</p> <pre><code>{"Message":"A Test Message encoded","Title":"My Message","Height":10,"GenericData":"Empty"} </code></pre> <p>which gives me an "Unexpected Token" if I try to use JSONLint to Parse it. Of course, if I type it in by hand to JSONLint then it is fine. I imagine there is some character I can't identify/see showing up in the JSON but am not sure how to find it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload