<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	PHP 5 以下版本兼容
*
*	$Id: compat.php,v1.0 12:25 2010-4-18 Lay $
*/


//stripos
if(!function_exists('stripos')) {
	function stripos($haystack, $needle, $offset = 0) {
		return strpos(strtolower($haystack), strtolower($needle), $offset);
	}
}

//json_encode
if (!function_exists('json_encode')) {
	
	require_once dirname(__FILE__).'/../class/json.php';
	
	function json_encode($arg)
	{
		global $services_json;
		if (!isset($services_json)) {
			$services_json = new Services_JSON();
		}
		return $services_json->encode($arg);
	}
}

//json_decode
if (!function_exists('json_decode')) {
	
	require_once dirname(__FILE__).'/../class/json.php';
	
	function json_decode($content, $assoc=false) {
		if ($assoc) {
			$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
		}
		else {
			$json = new Services_JSON;
		}
		return $json->decode($content);
	}

}

if (!function_exists('property_exists')) {
    /**
     +----------------------------------------------------------
     * 判断对象的属性是否存在 PHP5.1.0以上已经定义
     +----------------------------------------------------------
     * @param object $class 对象实例
     * @param string $property 属性名称
     +----------------------------------------------------------
     * @return boolen
     +----------------------------------------------------------
     */
    function property_exists($class, $property) {
        if (is_object($class))
         $class = get_class($class);
        return array_key_exists($property, get_class_vars($class));
    }
}

//读取数据
if(!function_exists('file_put_contents')) {
	function file_put_contents($filename, $s) {
		$fp = @fopen($filename, 'w');
		@fwrite($fp, $s);
		@fclose($fp);
		return TRUE;
	}
}

?>