Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Unable to use extension

I am following the hello world tutorial and have loaded the extension in php.ini and restarted the server. I was able to compile to a .dll and a .so. But in both cases it is saying the following error:

Fatal error: Uncaught Error: Class 'Utils\Greeting' not found in C:\git\tests.php:6 Stack trace: #0 {main} thrown in C:\git\tests.php on line 6

This is the actual code:

namespace Utils;
class Greeting
{
    public static function say()
    {
        echo "hello world!";
    }
}

This is my implementation:

<?php 
echo Utils\Greeting::say(), "\n";
?>

Surprisingly it works from the cli like...... php tests.php

edited Mar '16

I got the .so and .dll working half way. I am able to see the results in PHP Development server for Zephir examples but in case of apache 2.4 it gives a fatal error saying

Fatal error: Uncaught Error: Class 'Utils\Greeting' not found in C:\git\test\tests.php:6 Stack trace: #0 {main} thrown in C:\git\test\tests.php on line 6.

Is there a specific Apache configuration I need to follow? Here are my env details: I am on PHP 7.0.3 TS X64, Windows 10, Apache 2.4 server, i3 processor and X64 Machine. Is this a known issue with Apache or is it configuration issue

The code I am running:

<?php 
echo Utils\Greeting::say(), "\n";
$f = new Utils\Filter();
$f->alpha("hello");*

The extension code:

filter.zep

namespace Utils;
class Filter
{
    public function alpha(string str)
    {
        char ch;
        for ch in str {
            echo ch, "\n";
        }
    }
}

greeting.zep

namespace Utils;
class Greeting
{
    public static function say()
    {
        echo "hello world!";
    }
}

PHP Dev Server http://picpaste.com/zipher%5extension%5running%5php%5dev%5server.png

Apache Server http://picpaste.com/zipher%5extension%5apache%5error-P5j1FPaw.png

It seems to me PHP dev sever use php cli ini file, but Apache use different php.ini. You can check if your extension is loaded by using phpinfo(); function. Could you please double check this?

I do not have it enabled in php.ini through phpinfo();. But have it enabled and it shows in php -m command.



405
Accepted
answer
edited Mar '16

Ok, update: It is now working. I reinstalled Apache and started new Service. Strange though.