Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't require mage.php from an interactive shell

Tags:

php

magento

I would like to try some code snippets (about to make a script) which uses Magento's models and classes.

The problem is that I get the following error:

fdr@fderose-gtrade:/var/www/globaltrade$ 
fdr@fderose-gtrade:/var/www/globaltrade$ php -a 

Interactive shell
php > require  './app/Mage.php';
Fatal error: Class 'Mage' not found in /var/www/globaltrade/app/Mage.php on line 31

Line 31 of Mage.php is the following:

Mage::register('original_include_path', get_include_path());

Does anybody have an idea about what could be the cause? Thank you!

like image 220
fdierre Avatar asked Aug 03 '10 16:08

fdierre


People also ask

How do I run PHP interactive shell?

The CLI SAPI provides an interactive shell using the -a option if PHP is compiled with the --with-readline option. As of PHP 7.1. 0 the interactive shell is also available on Windows, if the readline extension is enabled. Using the interactive shell you are able to type PHP code and have it executed directly.

What is a PHP shell?

PHP web shell backdoors are basically malicious scripts and programs that are designed to perform a variety of malicious actions on your site. Simple web shells are command-based scripts. A PHP web shell allows attackers to manage the administration of your PHP server remotely.


2 Answers

According to php.net

Autoloading is not available if using PHP in CLI interactive mode.

see http://php.net/manual/en/features.commandline.interactive.php for more info (its a note towards the bottom of the description)

like image 83
sbditto85 Avatar answered Oct 27 '22 22:10

sbditto85


At first glance it seems that your issue stems from autoload. When you include your Mage.php file it appears that it then tries to run a php autoload and use the Mage class, but is failing in doing so. It's possible that the way that their autoload is functioning, the paths may not be correct when run from an interactive shell.

like image 2
asnyder Avatar answered Oct 27 '22 23:10

asnyder