Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Object $this problems in php5
Old 12-24-2007, 03:56 PM Object $this problems in php5
Junior Talker

Posts: 2
Name: Rodrigo
Trades: 0
Hello, first off, Merry Christmas to all and Happy Holidays.

I am new here and I am testing the waters. I am NOT a PHP programmer, but I've been working with PHP for a couple of years.

My webhost upgraded to PHP5 recently and a customized script I am using for osCommerce is giving me headaches. The script looks like this:

PHP Code:
$products_array[] = array('id' => $prid,
                                    
'name' => $products['products_name'],
                                    
'model' => $products['products_model'],
                                    
'price' => $products_price,
                                    
'quantity' => $this->contents[$products_id]['qty'],
                                    
'weight' => $products['products_weight'],
                                    
'tax_class_id' => $products['products_tax_class_id']); 
When visiting this page, quick_order.php, the error message I get is:

Fatal error: Using $this when not in object context in /home/xxxxxx/public_html/catalog/quick_order.php on line 184

Line 184 is:

PHP Code:
'quantity' => $this->contents[$products_id]['qty'], 
Can anyone point me in the right direction to fix this issue? If you need more info, I would be happy to oblige.

Thanks in advance,
Rodrigo
RodrigoDC is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-24-2007, 05:37 PM Re: Object $this problems in php5
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Merry Christmas!

$this is reserved to an object class when referring to functions and varibles within the internal structure of a class. So you have to use the var name used to assign the object.

Perhaps its $cart for example.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 12-24-2007, 06:10 PM Re: Object $this problems in php5
Junior Talker

Posts: 2
Name: Rodrigo
Trades: 0
MMM, thanks mgraphic, and Merry Xmas to you too. I realize this calls a variable somewhere else.

I did search for all php files within my catalog directory that contain the variable $this->contents, to no avail. Only the file that contains the code above is listed on the search.

I played around by replacing the variable for something like:

$contents[$products_id]['qty']

The above eliminates the error message (so those commenting out the line), but the form does not work properly (I failed to mentioned that the code is for a form to be submitted to add products to my shopping cart).

Am I doing the right thing? Otherwise, what do I need to look for to replace the $this variable?

Any help would do.

Thanks,
Rodrigo
RodrigoDC is offline
Reply With Quote
View Public Profile
 
Old 12-24-2007, 06:26 PM Re: Object $this problems in php5
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I am used to ZenCart, which is a spinoff from osCommerce, and it stores cart vars in a session varible. So you might try
$_SESSION['cart']->contents[$products_id]['qty']

You can always print out all of the global varibles too.
print_r($GLOBALS);

Once you do that, take a look at the source code, and look for the contents array.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 12-25-2007, 10:39 PM Re: Object $this problems in php5
Banned

Posts: 7
Trades: 0
$this used only inside class only


< link drop removed >

Last edited by chrishirst; 12-26-2007 at 03:16 PM..
sukosari is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Object $this problems in php5
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15508 seconds with 12 queries