3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Point { public $X; public $Y; function __construct($X, $Y) { $this->X = $X; $this->Y = $Y; } } $moves = 4; $mouseX = 0; $mouseY = 0; $point = new Point(400, 400); //$startAngle = rand(0, 90); $startAngle = 30; echo 'Angle = '.$startAngle."\r\n"; $angles = array($startAngle); for ( $i=1; $i<$moves; $i++ ) { $angles[$i] = $angles[$i-1] + (90 - 2*$startAngle)/($moves-1); } $lineHeightDiv = 0; foreach ( $angles as $angle ) { $lineHeightDiv += sin($angle*pi()/180); } $lineHeight = (($point->Y-$mouseY)/$lineHeightDiv)/$moves; echo 'LineHeight = '.$lineHeight."\r\n"; $lineWidthDiv = 0; foreach ( $angles as $angle ) { $lineWidthDiv += cos($angle*pi()/180); } $lineWidth = (($point->X-$mouseX)/$lineWidthDiv)/$moves; echo 'LineWidth = '.$lineWidth."\r\n"; $points = array(new Point($mouseX, $mouseY)); for ( $i=1; $i<=$moves; $i++ ) { $x = $points[$i-1]->X + $lineWidth*cos($angles[$i]*pi()/180); $y = $points[$i-1]->Y + $lineHeight*sin($angles[$i]*pi()/180); $points[] = new Point($x, $y); } var_dump($points);
Output for 5.3.0 - 7.1.0
Angle = 30 LineHeight = 36.037887193993 LineWidth = 36.037887193993 Notice: Undefined offset: 4 in /in/4qa6P on line 47 Notice: Undefined offset: 4 in /in/4qa6P on line 48 array(5) { [0]=> object(Point)#2 (2) { ["X"]=> int(0) ["Y"]=> int(0) } [1]=> object(Point)#3 (2) { ["X"]=> float(27.606623226707) ["Y"]=> float(23.16470736758) } [2]=> object(Point)#4 (2) { ["X"]=> float(50.771330594287) ["Y"]=> float(50.771330594287) } [3]=> object(Point)#5 (2) { ["X"]=> float(68.790274191284) ["Y"]=> float(81.981056403003) } [4]=> object(Point)#6 (2) { ["X"]=> float(104.82816138528) ["Y"]=> float(81.981056403003) } }
Output for 5.0.0 - 5.2.17
Angle = 30 LineHeight = 36.037887193993 LineWidth = 36.037887193993 Notice: Undefined offset: 4 in /in/4qa6P on line 47 Notice: Undefined offset: 4 in /in/4qa6P on line 48 array(5) { [0]=> object(Point)#2 (2) { ["X"]=> int(0) ["Y"]=> int(0) } [1]=> object(Point)#3 (2) { ["X"]=> float(27.606623226707) ["Y"]=> float(23.16470736758) } [2]=> object(Point)#4 (2) { ["X"]=> float(50.771330594287) ["Y"]=> float(50.771330594287) } [3]=> object(Point)#5 (2) { ["X"]=> float(68.790274191284) ["Y"]=> float(81.981056403003) } [4]=> object(Point)#6 (2) { ["X"]=> float(104.82816138528) ["Y"]=> float(81.981056403003) } }
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/4qa6P on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/4qa6P on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/4qa6P on line 4
Process exited with code 255.