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 8147761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:27:22+00:00 2026-06-06T14:27:22+00:00

I’m relatively new to php development but not to web development in general. I

  • 0

I’m relatively new to php development but not to web development in general.

I have the following php file:

<?php
class dialogResult{

    var $Message;
    var $Title;
    var $Height;
    var $GenericData;

     function __construct(){
        $this->Height = 10;
    }
}

   header("Cache-Control: no-cache", true);
   header("Content-type: application/json; charset=utf-8", true);
   $dr = new dialogResult();
   $dr->Message = "A Test Message encoded";
   $dr->Height = 10;
   $dr->GenericData = "Empty";
   $dr->Title = "My Message";
   echo(json_encode($dr));
?>

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?

It doesn’t have to be just moving this class, if I have ANY included file it makes the data invalid.

Thanks,

Keith

Here is the include class, I’ve also tried removing the ?>

<?php

class dialogResult{

    var $Message;
    var $Title;
    var $Height;
    var $GenericData;

     function __construct(){
        $this->Height = 10;
    }
}

There are no leading or trailing spaces anywhere. Here is the ‘invalid’ JSON that is returned:

{"Message":"A Test Message encoded","Title":"My Message","Height":10,"GenericData":"Empty"}

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.

  • 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-06T14:27:25+00:00Added an answer on June 6, 2026 at 2:27 pm

    Even Martin and navnav comments are right, but whitespaces usually don’t invalid the Json format as they can do with binary formats (eg. GIF, JPEG, etc.).

    So your problema can be the BOM header a 2/3 byte header that many editors don’t show or, worse, add, at the beginning of the file.

    EDIT

    A possible way to remove BOM is to use and IDE like phpstorm, having a binary safe editor, able to detect and remove BOM.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a reasonable size flat file database of text documents mostly saved in

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.