Ver código fonte

[php][php7] check STD constants are defined before using them (fixes #6176)

Alexander Kuzmenko 8 anos atrás
pai
commit
c7116097c3
2 arquivos alterados com 12 adições e 6 exclusões
  1. 6 3
      std/php/_std/Sys.hx
  2. 6 3
      std/php7/_std/Sys.hx

+ 6 - 3
std/php/_std/Sys.hx

@@ -114,15 +114,18 @@
 	}
 
 	public static function stdin() : haxe.io.Input {
-		return untyped new sys.io.FileInput(__php__("STDIN"));
+		var p = untyped __php__("defined('STDIN') ? STDIN : fopen('php://stdin', 'r')");
+		return untyped new sys.io.FileInput(p);
 	}
 
 	public static function stdout() : haxe.io.Output {
-		return untyped new sys.io.FileOutput(__php__("STDOUT"));
+		var p = untyped __php__("defined('STDOUT') ? STDOUT : fopen('php://stdout', 'w')");
+		return untyped new sys.io.FileOutput(p);
 	}
 
 	public static function stderr() : haxe.io.Output {
-		return untyped new sys.io.FileOutput(__php__("STDERR"));
+		var p = untyped __php__("defined('STDERR') ? STDERR : fopen('php://stderr', 'w')");
+		return untyped new sys.io.FileOutput(p);
 	}
 
 	public static function getChar( echo : Bool ) : Int {

+ 6 - 3
std/php7/_std/Sys.hx

@@ -121,15 +121,18 @@ import sys.io.FileInput;
 	}
 
 	public static function stdin() : haxe.io.Input {
-		return @:privateAccess new FileInput(Const.STDIN);
+		var p = Global.defined('STDIN') ? Const.STDIN : Global.fopen('php://stdin', 'r');
+		return @:privateAccess new FileInput(p);
 	}
 
 	public static function stdout() : haxe.io.Output {
-		return @:privateAccess new FileOutput(Const.STDOUT);
+		var p = Global.defined('STDOUT') ? Const.STDOUT : Global.fopen('php://stdout', 'w');
+		return @:privateAccess new FileOutput(p);
 	}
 
 	public static function stderr() : haxe.io.Output {
-		return @:privateAccess new FileOutput(Const.STDERR);
+		var p = Global.defined('STDERR') ? Const.STDERR : Global.fopen('php://stderr', 'w');
+		return @:privateAccess new FileOutput(p);
 	}
 
 	public static function getChar( echo : Bool ) : Int {