Date problem

Using Date on php results in error “Error Exception: Non-static method Date_TimeZone::isValid() should not be called statically”.
Haxe-version: 4.0.5
PHP (Strato): 7.3

Code

import php.Web;
import php.Lib;
import haxe.Serializer;
import haxe.Unserializer;

class Server {
	// *******************
	public function new() {}
	
	// *************************************
	public static function main() {
		var callbackName = php.Web.getParams().get("callback");
		var mimetype = "application/json";	
		if (callbackName != null) {
			mimetype = "application/javascript";
		}
		Web.setHeader("Content-Type",mimetype);
		Web.setHeader("Connection","close");
		Web.flush();
		
		var d1 = Date;				// OK
		var d2 = Date.now();		// Error
		
		var response = "OK";		
		var json:String = haxe.Json.stringify({serializedResponse:Serializer.run(response)});
		if (callbackName != null) {
			json = callbackName + "(" + json + ")";
		}
		Web.setHeader("Content-Length",(""+json.length));
		Lib.println(json);
		Web.flush();
	}
}

Compiled with:
-main Server
-debug
-php Program/PHP

Are you sure you posted the full sample?
I can’t reproduce it. And there’s no single isValid call in the whole standard library.

Make sure your code doesn’t clash with libs installed from PEAR. They have a toplevel Date class too.
Try building your project with -D php-prefix=my.company or --php-prefix my.company (Haxe 3) to put your Haxe code into it’s own package structure, then you should be safe.

Note: If you run a Haxe 3 project and use resources, you’ll have to manually put them into the correct subfolder.

1 Like

Wow, worked !