Posting to Blogger using PHP

陌路散爱 提交于 2019-12-03 03:46:35

Your $gdClient variable is intanciated outside of the createPublishedPost function :

$gdClient = new Zend_Gdata($client); 

Inside a function, the variables that have been defined outside of it don't exist by default.
About that, you can take a look at the Variable scope page of the manual.

This means $gdClient doesn't exist inside the function ; hence, it is null ; so, not an object -- which explains the error message you are getting.


To check that by yourself, you can use

var_dump($gdClient);

at the beginning of the function : it will allow you to see what kind of data it is ; if it's not an instance of the class you are willing to use, it's not a good sign ;-)


You might want to either :

  • pass that variable as a parameter to the createPublishedPost function
  • or declare it as global inside the function (so the function can "see" the variable as declared outside)

The first solution is probably the cleanest one, I think ;-)


As a sidenote, you might want to configure your error_reporting level (see also), so you get an E_NOTICE when you are using a variable that is not declared -- in this case, you should have gotten one, for instance ;-)
You might also want to enable display_errors, on your development machine, if it's not already on -- seems to be, as you got the Fatal error message

It might seem a bit annoying at the beginning, but, once you get used to it, it is really great : allow to detect that kind of stuff a lot quicker ;-)
And it also helps detect typos in variable names ^^
And it makes you code way cleaner !

user704992

Moving the $gdClient to the function body fixed something, but you also have to move the $blogID into the function body.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!