Link to home
Start Free TrialLog in
Avatar of kkbenj
kkbenj

asked on

PHP invalid object initializer

Firebug is reporting an invalid object initializer:
invalid object initializer
[Break On This Error] firstname: { (line 313)

But I am very confused.  Line 313 isn't working with firstname.  I will attach the code line #'s.

Any help is greatly appreciated!
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Firebug can only see the browser output.  PHP creates the browser output, but Firebug cannot see the PHP code, because Firebug is running on the client machine, whereas PHP is running on the server.
Avatar of kkbenj
kkbenj

ASKER

So I should ignore the error?
It is definitely not a PHP script error.
In your browser open the source of the page where you get this error and view in the source to line 313.
Probably it's a javascript error of some kind.

Hope this helps
I agree with webtronick.   I have asked the moderators to add the question to the JavaScript Zone.  Leave the question open for a day and I am sure you will get a good answer (there are some pretty sharp experts watching the JS Zone).  Best of luck with it, ~Ray
Avatar of Mark Brady
You never attached your javascript code. What the experts said above is correct. This is nothing to do with PHP. It is javascript and this error comes up only in Firebug as far as I know. What it usually means is there is a typo or something out of place in your javascript so firebug will flip out and throw this error.
If you can please post your javascript code (the entire script would be very helpful) I will help find the error and fix it for you.
>>Firebug is reporting an invalid object initializer:
a valid object starts with a "{" followed by a "key" followed by a colon followed by a "value" followed by a "}" - ex::
var data ={"firstname":"John"}

where "firstlname" is the "key" and "John" is the "value".  In javascript, if there are no spaces in the key, then the quotes are optional - ex:
var data ={firstname:"John"}

The value can be a sting, a number, an object, or even an array of "things" (which can be a mix of strings, numbers, objects, and even arrays).

To get the error you mentioned "Invalid Object Initializer", then you must have INVALID Object syntax.
The following are all WRONG Ex:
a. var data ={first name:"John"}; //if the "key" has spaces, it must be enclosed in quotation marks

b. var data={firstName:John}; //if the value is a "string" it needs to be enclosed in quotation marks

c. var data={"firstname"};// the {} tells javascript you are attempting to create an object, and an object needs to have a key and a value. So, on this example the object "notation/syntax" is basically "incomplete"

d. var data={"firstname":{"John"} };// this is the same problem as the one above. However, the problem is with the "nested" object.  The outermost object is OK since it has a key=> "firstname" and a value =>{} (which is "some object").  However, "some object" is not correct since it has the same problem outlined in "c" above.  To fix it you would need to:
 i.) get rid of the inner braces - var data={"firstname": "John" };
OR
ii.) provide a valid object notation for the inner object - var data={"firstname": {"John": 23} };
Avatar of kkbenj

ASKER

This is very thorough, hielo.  Thank you.

But I am VERY confused by the error, as it indicates PHP lines of code.  Thought I had attached but will do so now.
<li class='required-field'>
<label>
   Last Name
<em>*</em>
</label>
<?php				  
if (isset($_POST["lastname"])) {				  
	echo "<input name='lastname' type='text'  value='".$_POST["lastname"]."'/>";
} else {
	echo "<input name='lastname' type='text'/>";
}    (this is line 313)
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Looking at some of your other problems I see:

firstname: {
                        "required"
                    },

THAT is a problem. It is definitely an invalid initializer, so that code would trigger the error you are reporting.  You would need to change it to:

firstname:"required",

OR to:
firstname: {
				"required": true
			  },

Open in new window

Avatar of kkbenj

ASKER

Great explanation of how to troubleshoot!  The error was actually eliminated by fixing the firstname:"required" as you suggested.