Forum Moderators: coopster

Message Too Old, No Replies

Very Newbie With PHP Code Problem

Don't understand code

         

Fallen Angel

1:55 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



Hi, I am very, very, very new to php and also to this site as I just found it, am hoping that there are some genius's around that may be able to help with a problem I have struggled with for days.

I have an oscommerce site and have installed a newsletter products contribution as directed by the developer but have come up with problems. Understandably the developer is very busy and has not been able to get back to me, I have searced oscommerce site for answers and experts exchange and although help is excellent, it doesn't come very fast and I don't mean that in a nasty way, just that this has taken days!

the error message i was getting was:

Warning: reset() [function.reset]: Passed variable is not an array or object in /home/example/public_html/store/admin/includes/classes/object_info.php on line 17

Warning: Variable passed to each() is not an array or object in /home/example/public_html/store/admin/includes/classes/object_info.php on line 18

i was advised:

change the objectInfo() function to the following. Then, it will tell you exactly where in the code the bad call is being made:

function objectInfo($object_array) {
if (!is_array($object_array) &&!is_object($object_array)) {
echo "*** ERROR FOUND ***";
var_dump($object_array);
debug_print_backtrace();
die();
}
reset($object_array);
while (list($key, $value) = each($object_array)) {
$this->$key = tep_db_prepare_input($value);
}
}

I did this and this is what I got:

*** ERROR FOUND ***bool(false) #0 objectInfo->objectInfo() called at [/home/example/public_html/store/admin/newsletters.php:229]

I was advised:

What's happening at /home/example/public_html/store/admin/newsletters.php on line 229?

Keep doing this style of debugging, until you find something that doesn't make sense. Probably there is some database call that is trying to initialize the object with 0 records.

And now I'm stuck!

I have looked at the code at /home/example/public_html/store/admin/newsletters.php on line 229 but because I don't understand a thing about it, although I really have tried, I don't even know what I am looking at.
Can anyone help please?
Thank you in advance

[edited by: dreamcatcher at 2:07 pm (utc) on Nov. 14, 2007]
[edit reason] Removed specifics. [/edit]

mojomartini

2:34 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



I'm not an expert but ... can you show us line 229 so that we can see what it is?

Thanks..

Fallen Angel

3:24 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



Hi there,

thank you for responding.

The code on line 229 is

$nInfo->objectInfo($newsletter);

Many thanks

PHP_Chimp

4:54 pm on Nov 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will need to look further back. Where the the $newsletter variable coming from?
The other option is that the whole class $nInfo is not working...so are you using that class in any other places and if so are you getting errors there.
Or that the objectInfo method within that class is not working...so again are you using that anywhere else, and if so is it working there?

Hopefully the problem will be from $newsletter.

Fallen Angel

5:23 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



Hi PHP_Chimp,

Thanks for your reply. Could you have a look at these two pages for me to see if the problem is there as I don't know what I'm looking at. I'd be very grateful.

<removed large code dump as it is not needed>

thanks very much for your help

[edited by: eelixduppy at 11:07 pm (utc) on Nov. 14, 2007]

PHP_Chimp

7:54 pm on Nov 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wow that is a lot of code...

To save the mods some work you should remove all links when you post the code, as you will find everything gets turned into example.com. Dont worry every one forgets at some point.

The report that you are getting from the debug_backtrace is not mentioning any included files...however that doesnt always mean that the problem doesnt stem originally from an included file.

The var_dump is saying that there is nothing in the $newsletter variable. So that is your problem, however why it is blank is another question.

The first php file is just a load of constants that are getting defined for use everywhere. There should be an include 'constants.inc'; at the top to make sure those constants are getting passed along to the other pages. As you dont have that at the top of the other code you posted so is there other included/required(_once) files listed?
You are looking for a group of code that starts with -
class <some_name> {
function objectInfo($something) {
...
}
in any other included files. This may be a class called objectInfo, in which case as you are trying to add content to its contructor you would need to call it in a different way -
$nInfo = new objectInfo($newsletter); Although this only helps when there is actually something in $newsletter ;)

Also it may be quicker to ask the people that wrote the code. Although I am assuming this is old code as it is using the $HTTP_GET_VARS as opposed to $_GET, so there may well be an up-to-date version of the code around. Not that $HTTP_* are wrong, just depreciated old form.

Also the code that you posted was not the set of code from the file with the original error on line 229. So in that file are there other included files, or the class that objectInfo belongs to.

It may be worth adding error_reporting [uk3.php.net](E_ALL); to the top of all of your pages while you test. As this will hopefully help you with any errors that may not be getting through to you. Also if you see @ before any functions then remove it while testing as this is used to mute errors, so there may be others errors hiding that will help you sort out this one.

Fallen Angel

9:40 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



Oh dear, I think that this is way, way over my head.

I really appreciate the time that you've spent on this PHP_Chimp but I really don't understand any of it.

Maybe my site isn't destined to send newsletters with my products in it!

Many, many thanks for your efforts.

PHP_Chimp

10:09 pm on Nov 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What you are using is a class structure or object orientated programming (oop). There are loads of tutorials about them on the web, so have a look through and you should be able to pick it up.
If its not working then maybe take it off the site for the moment, but stick with it and it should all make sense soon. Then you should be able to sort it out and get it to work.

Start with this from the manual - [php.net...]

Fallen Angel

10:42 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



Thank you for your help and patience.

I will follow your advice, I don't usually like to quit and hopefully like you say maybe one day I'll get the hang of it.

Thanks again, its much appreciated.

phranque

3:12 am on Nov 15, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], fallen angel!
you might want to check out the php forum charter [webmasterworld.com] for some php resources and forum guidelines.

Fallen Angel

1:32 pm on Nov 15, 2007 (gmt 0)

10+ Year Member



Thank you for the welcome phranque,

And for the advice to help me proceed.

Much appreciated.