JSON uses object-oriented notation, not array notation. Try the -> instead of the brackets and quotes.
Also, trying to "do it all on one line" is a fools errand. That kind of code makes it harder to debug and understand the data structures. Use as many statements as needed, no less, no more! http://www.laprbass.com/RAY_temp_tonelm54.php
<?php // RAY_temp_tonelm54.phperror_reporting(E_ALL);$jso = <<<EOD{"type" : "combo","attribute" : "SQL","values" : "Select distinct `First Name` from `staff`;"}EOD;// DECODE THE STRING INTO AN OBJECT$obj = json_decode($jso);// ACTIVATE THIS TO SEE WHAT IS IN THE OBJECT// var_dump($obj);// WHAT IS IN THE type PROPERTYvar_dump($obj->type);
greetings tonelm54, , not sure about how you "think" about the methods you use in your code, as you have a PHP ['type'] array access for what you have as a javascript object in the javascript object notation string. I have to work in PHP and javascript at the same time to build pages, and often get mixed up in the code syntax for each,
In javascript you are allowed to access OBJECT properties with array methods like - jsobj['type'] - , but in PHP this is not allowed, , I often forget which Object access to use, and put -> in javascript and put a "." in PHP, which causes fatal errors in either one.
If you are used to javascript, you will need to watch your code when changing to PHP code writing, as many things like ['type'] for object access will get you -
Parse error: syntax error, unexpected '['
and -
switch (json_decode($rowNewInput['json'])->type) {
just might work
but if I forget and use -
switch (json_decode($rowNewInput['json']).type) {
it does Not work.
for your own development error trace, I have found that compound abstraction code like -
switch (json_decode($rowNewInput['json'])->type) {
is harder to debug.
I like this better for debugging -
$newIn = json_decode($rowNewInput['json']);
switch ($newIn->type) {
because you can more clearly see what line and method causes the error
0
Featured Post
Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.
One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption. Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Originally, this post was published on Monitis Blog, you can check it
here
.
In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions.
Consider email address RFCs:
Look at HTML5 form input element (with type=email) regex pattern:
T…