PHP Parts Property - php

I'm working on some code written by another developer and it is written in PHP. There is a line of code that is causing an error. I'm thinking that it is something you have to enable for PHP because it works just fine in another environment but doesn't work on the new environment and I haven't changed the code yet. The line is:
$structure->parts
$structure is a variable I've passed in but from a search online parts is a property. The error I'm getting says:
Undefined property: stdClass::$parts
Thanks for any help or ideas anyone might have.

Looks like parts doesn't exist there. Try running var_dump($structure) to get a better picture of what you're really dealing with.

Related

The variable seems to be independent, but the program works fine. why?

I'm using the following library to give a update feature to my WordPress and this works fine with the code of documentation.
https://github.com/YahnisElsts/plugin-update-checker/blob/master/README.md
require 'plugin-update-checker/plugin-update-checker.php';
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://github.com/user-name/repo-name/',
__FILE__,
'unique-plugin-or-theme-slug'
);
But I'm really wondering where this '$myUpdateChecker' variable came from and how this is working, because I can't find any part of the library's files using this variable.
It seems to be totally independent for me.
Thank you in advance.
You're creating the variable right there. You can even name it something else if you want (eg. $update_checker), that shouldn't cause any issues in this particular case as the variable isn't being used anywhere else (according to your own words.)
For more details: PHP variables.

Accessing Object in PHP

I've some strange issues with some php code.
if ($user->userType=='admin'){
If I use the above command, the php engine just stop interpreting and display the code in plain text on my browser. On the other hand if I use the below method it works:
if ($user['userType']=='admin'){
Again here also:
$_SESSION['currentUser']->id
If I use the above code it just displays the rest of code as plain text:
id); // fail user }else{ $authentication="failed"; $noAuthPresentation="loginForm"; }
Why this is happening? It's a big project and I don't want to change every line where there is an occurrence of ->.
Do I need to change some setting somewhere? I'm using WAMP server with php 5.5.12.
Any help ? Thanks!
You're mixing up types, user is an array, and not an object. Something in your php config is doing something strange to your error display it seems. Right click on the page that has the errors, and view source if possible.
Does login.php contain html and php code by chance?

PHP, can't set variable via $_POST

I have a slightly frustrating problem...
I'm sending a form value to PHP via AJAX and that seem to work fine.
When I do var_dump in PHP I see my values I can also set a variable and echo it correctly.
However, the line
$prod_id=$_POST['product'];
causes an uncaught type error in the browser.
If I just set the variable with text in PHP everything works fine.
To conclude, this piece of code works fine:
$prod_id=("Slab Skate");
$selected_customers = mysqli_query($link,"SELECT * FROM customers
INNER JOIN cust_products on cust_products.cust_id=id
INNER JOIN products on products.prod_id=cust_products.product_id
WHERE products.prod_name='$prod_id'");
This code causes uncaught typerror:
$prod_id=$_POST['product']
Same SQL statement as above.
If I do
var_dump ($prod_id);
after setting it with $_POST I get:
string(10) "Slab Skate"
My form data in network headers tab of Chrome developer tools say:
product:Slab Skate
I don't get it...
Thanks in advance for any tips.
Update and some clarifications.
The error I get is this: "Uncaught TypeError: Cannot read property 'documentElement' of null" which is a Javascript error coming from a function later in the code. However, since the whole thing works if I "hardcode" the variable instead of setting it from $_POST my assumption was that the error must reside in PHP.
But maybe that's not the case...
What I'm doing is the following: posting a form value to PHP -> use value to select from my_sql and prepare an XML output. So far so good, (I can see the xml output in Chrome dev tools) but then I go back to a javascript to fetch the xml output from my PHP file and then it fails.
When thinking about it, it's rather obvious why it works with a "hardoded" variable and not with the $_POST set one.
So, I see two solutions either set the PHP variable in my_sql or using javascript more intelligently.
Do anyone have a smart solution? I could post all the code, but it's quite long.
Second update:
I solved the issue by writing an xml file to the server instead of trying to download it from the php file. Then my java function can process the xml correctly.
It does work, but I'm not sure how well it scales? It must be better to process the xml output from PHP directly rather then saving it to file first and then process. But, I have no insight on how big the difference is...
/Tim
I wouldn't use SELECT * FROM when using Inner Join if i were you. that would cause all sort of problems , simply give the names of columns.

zend layout.phtml error

Hi I've got an error in my Zend Framework project...
It raised:
Invalid controller specified (myweb)
Here is my apache error.log:
PHP Warning: Invalid argument supplied for foreach() in /var/www/myweb/application/layouts/scripts/layout.phtml on line 107
Here's my code in layout.phtml:
<?php foreach($this->category as $categories):?>
<li><div id="sidemenu"> �<?php echo $categories['categoriesName'];?></div></li>
<?php endforeach;?>
Can anybody help me?
The problem seems to be that for some reason your url is presenting myweb as the controller instead of what should be your controller.
My guess is the you are trying to use localhost to display your application so are presenting a url similar to http://localhost/myweb/...
While it is possible to use the localhost to view ZF applications it often becomes inconvenient as applications become more complex. I would suggest you use a vhost for anything more then a very simple application.
I'm pretty sure that when you resolve the url problem the php warning will likely fix itself.
It seems like the variable $this->category is not set in the Controller. You can do this by defining $this->view->category from your controller.
Mostly when using these controller generated variables in the layout script instead of the corresponding view script, you want to use the same data in every view. If this is the case, check this question: Sending variables to the layout in Zend Framework
This error come because your array $this->category is blank. if this is blank array or return nothing then how foreach loop will execute?
so first print this array and check.

RSS Parser for Twitter is Slow - why?

I am making use of this script to get the first item of my Twitter feed. However, it is slow (it takes 3 to 4 seconds to load page now). Why is it so slow?
Here is how I use it.
require_once 'rss_php.php'; //see link above
$rss = new rss_php;
$rss->load('http://twitter.com/statuses/user_timeline/XXXXXX.rss');
$feed = $rss->getItems(false, 1);
echo $feed[0]['title'];
echo $feed[1]['title'];
I do get this PHP notice:
Notice: Undefined variable: tempNode
in
C:\wamp\www\rss_php.php
on line 137
I don't know why since this works, line 137 is this line:
return $tempNode;
Thanks all for any help. I appreciate any advice on speeding this up.
Fetching content from a remote location can potentially introduce some rather ugly loading issues.
Try saving the contents of the RSS feed in a local file and see if the problem persists when loading from a local drive.
If this fixes the issue, you should look into caching the contents of the feed every once in a while.
Firstly, line 110 of your pastbin is assigning a variable that was never declared. As such, any requests or assignments to an undeclared variable will do this. From what I see it should be as simple as adding $tempNode = Array(); just below the function call of the extractDOM method.
Next, since this is a script from someone else I would recommend asking them what you can do to improve performance. From what is in the pastbin I don't see anything elaborate going on, nor do I see you using the library incorrectly, but ultimately they would know better.
After line 138 in rss_php.php (v.1 Free version) file paste this:
...
if (!isset($tempNode)){
$tempNode = null;
}
return $tempNode;
...
Enjoy
;)
Getting rid of that return $tempNode; notice is easy, but not your problem, it just needs to be defined out of the forloop in that extractDOM function.
Optimizing your php code is a big task. I'm assuming that the api call is the majority of the time, but if you want to try and speed your code up a bit I would look into tutorials on how to do that:
http://ilia.ws/archives/12-PHP-Optimization-Tricks.html
http://progtuts.info/55/php-optimization-tips/
http://hungred.com/useful-information/php-micro-optimization-tips/

Categories