php extern error...

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

php extern error...

tom rhodes
Hi,

i've got a feeling i'm doing something stupid but i just can't see it :(

i'm externing this php class...

<?php
/**
 * A simple PHP proxy class for the WURFL Web Service.
 * @author Charl van Niekerk 
 */

function makeWURFLWS()
{
return new WURFLWS();
}
 
class WURFLWS
{
   
    public static $defaultWebService = 'http://api.wurflws.com/wurflws';

public function __construct()
{
}
   
    public static function get($userAgent=NULL, $webService=NULL)
    {
        // If the user agent has not been passed as a parameter, read from the HTTP request.
        if ($userAgent === NULL) {
            $userAgent = $_SERVER['HTTP_USER_AGENT'];
        }

        // If the web service has not been passed as a parameter, use the default.
        if ($webService === NULL) {
            $webService = self::$defaultWebService;
        }

        // Compile the full URL.
        $url = $webService . '?ua=' . urlencode($userAgent);

        // Execute remote API call.
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        $result = curl_exec($curl);

        // Check if a result could be retrieved.
        if ($result === FALSE) {
            throw new Exception('WURFLWS: ' . curl_error($curl));
        }

        // Close the CURL handle resource.
        curl_close($curl);

        // Decode the returned data.
        $data = json_decode($result);

        // Check if the data could be properly decoded.
        if ($data === NULL) {
            throw new Exception('WURFLFS: ' . json_last_error());
        }

        return $data;
    }
}
?>

like this.,..

package ch1mp.ua;

extern class WURFLWS
{
public static var defaultURL:String;
static function __init__():Void untyped {
        __call__("require_once", "WURFLWS.class.php");
    }
public function new():Void
{
}
public static function get(?userAgent:String = null, ?webService:String = null):Dynamic;
}

it compiles fine, but at runtime i get this..."Fatal error: Class 'ch1mp_ua_WURFLWS' not found in...."

i'm already successfully externing another class based on the instructions on haxe.org. anyone know what i'm doing wrong here?

thanks,

tom.



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: php extern error...

Franco Ponticelli
add @:native("WURFLWS") to your class.

Franco

On Thu, Mar 10, 2011 at 1:54 PM, tom rhodes <[hidden email]> wrote:
WURFLWS


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: php extern error...

tom rhodes
thanks franco :)

that stops the fatal error, is that to do with the package?


On 10 March 2011 14:58, Franco Ponticelli <[hidden email]> wrote:
@:native("WURFLWS")


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: php extern error...

Franco Ponticelli
Yes, haxe/php flattens the packagename+class name ... this way you point exactly at what you need.

Franco

On Thu, Mar 10, 2011 at 2:21 PM, tom rhodes <[hidden email]> wrote:
thanks franco :)

that stops the fatal error, is that to do with the package?


On 10 March 2011 14:58, Franco Ponticelli <[hidden email]> wrote:
@:native("WURFLWS")


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org