theGreenCabbage
theGreenCabbage

Reputation: 4845

Undefined index within a PHP path

Newbie here to OpenCart extension development. I am currently developing a 99Bill (Chinese payment method) payment extension.

Currently, I've added new files to the MVC directories (so, I added files under admin, catalog, etc, where I named my extension bill99, since PHP doesn't allow names that start with numbers).

I was trying to test my extension, but on my OpenCart home page, I get the following error:

Notice: Undefined index: mobile_description in /vagrant/opencart/upload/catalog/model/catalog/product.php on line 20
Notice: Undefined index: mobile_description in /vagrant/opencart/upload/catalog/model/catalog/product.php on line 20
Notice: Undefined index: mobile_description in /vagrant/opencart/upload/catalog/model/catalog/product.php on line 20
Notice: Undefined index: mobile_description in /vagrant/opencart/upload/catalog/model/catalog/product.php on line 20
Notice: Undefined index: mobile_description in /vagrant/opencart/upload/catalog/model/catalog/product.php on line 20
Notice: Undefined index: mobile_description in /vagrant/opencart/upload/catalog/model/catalog/product.php on line 20

I am not quite sure how I triggered it, since I never edited or touched the product.php file before. The error appears even if I disable/uninstall my 99Bill extension.

When I navigate to product.php, line 20 simply says:

'description'      => $query->row['mobile_description']

I have a feeling my error has nothing to do with the product.php file, since I never touched it before, and likely relates to my 99Bill extension. I may have not initialized a class somewhere.

For someone that's had this error before, could you help me understand this?

Upvotes: 0

Views: 1807

Answers (1)

Elias Van Ootegem
Elias Van Ootegem

Reputation: 76395

Well: line 20 accesses an array index, doesn't it? Suppose the index doesn't exist, wouldn't the error message you get make sense then? try dumping the contents of $query->row or replace what you have now with:

'description'      => isset($query->row['mobile_description']) ? $query->row['mobile_description'] : null,

As far as why you get this notice: This answer explains that, and contains some snippets that could help you refactoring your code

Upvotes: 2

Related Questions