3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Unit { /** * checkMapzone * 检测mapzone * @param mixed $params * @static * @access public * @return void */ public static function checkMapzone($params) { $allRegion = array( array( 'provinceId' => 100000, 'cityIds' => array(), ), ); $mapzone = $params['mapzone']; $mapzone = self::__checkMapzoneFormat($mapzone); $provinceIds = Tools\Common::array_column($mapzone, 'provinceId'); if (in_array(100000, $provinceIds)) { $params['mapzone'] = \App::jsonEncode($allRegion); return $params; } $idToCityMap = \App::getConf('city')['idToCityMap']; foreach ($mapzone as $area) { if (!array_key_exists($area['provinceId'], $idToCityMap)) { throw new UserException("无效的省份"); } foreach ($area['cityIds'] as $cityId) { if (!array_key_exists($cityId, $idToCityMap[$area['provinceId']]['value'])) { throw new UserException("无效城市"); } } } $params['mapzone'] = \App::jsonEncode($mapzone); return $params; } /** * __checkMapzoneFormat * 检测mapzone格式是否正确 * @param mixed $mapzone * @static * @access private * @return void */ public static function __checkMapzoneFormat($mapzone) { $dec = json_decode($mapzone); if (!is_array($dec)) { throw new \Exception("投放地域格式错误"); } $mapzone = json_decode($mapzone, true); foreach ($mapzone as $key => $area) { if (!isset($area['provinceId']) || preg_match(GeneralMatch::POSITIVE_INTEGER, $area['provinceId']) != 1) { throw new \Exception("mapzone格式不正确(provinceId)"); } $mapzone[$key]['provinceId'] = intval($area['provinceId']); if (!isset($area['cityIds']) || !is_array($area['cityIds'])) { throw new \Exception("mapzone格式不正确(cityIds)"); } foreach ($area['cityIds'] as $k => $cityId) { if (preg_match(GeneralMatch::POSITIVE_INTEGER, $cityId) != 1) { throw new \Exception("mapzone格式不正确(cityIds)"); } $mapzone[$key]['cityIds'][$k] = intval($cityId); } } return json_encode($mapzone); } } $params['mapzone'] = '[{"provinceId":"19","cityIds":[59]}]'; $params['mapzone'] = Unit::__checkMapzoneFormat($params); echo $params['mapzone'];
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: json_decode(): Argument #1 ($json) must be of type string, array given in /in/iJbJM:54 Stack trace: #0 /in/iJbJM(54): json_decode(Array) #1 /in/iJbJM(83): Unit::__checkMapzoneFormat(Array) #2 {main} thrown in /in/iJbJM on line 54
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
45.63 ms | 401 KiB | 8 Q