I have this code in Magento (installed on Windows 10):

$rootMagento = Mage::getBaseDir();
$files = scandir($rootMagento);
$count = sizeof($files);
for ($i =0; $i< $count; $i++) {
    if ($files[$i]=='productData.txt'){
        $fileAperto = fopen($files[$i], "r");
        while (!feof($fileAperto)){
            $nome = trim(substr($buffer,0,20));
            if ($nome =='') {
                Mage::log ('manca il nome');


and, when I run it, I have this error:

Fatal error: Call to a member function getOptions() on a non-object in C:\xampp\htdocs\magento\app\Mage.php on line 329

I try also to print some variable's value but system.log file is always empty.


If you want to use Magento in a custom PHP script, you always have to initialize it first:


Afterwards, Mage::getBaseDir() will not throw this error anymore

  • @Federica. Welcome to SE. If an answer helped you solve your problem, mark it as accepted. – Marius Aug 24 '16 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.