本文整理汇总了PHP中get_resource_type函数的典型用法代码示例。如果您正苦于以下问题:PHP get_resource_type函数的具体用法?PHP get_resource_type怎么用?PHP get_resource_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_resource_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getExceptionTraceAsString
/**
* @param \Exception $exception
* @return string
* @todo Fix this to get full stack trace
*/
public static function getExceptionTraceAsString(\Exception $exception)
{
$ret = "";
$count = 0;
foreach ($exception->getTrace() as $trace) {
$args = "";
if (isset($trace['args'])) {
$args = array();
foreach ($trace['args'] as $arg) {
if (is_string($arg)) {
$args[] = "'" . $arg . "'";
} elseif (is_array($arg)) {
$args[] = "Array";
} elseif (is_null($arg)) {
$args[] = 'NULL';
} elseif (is_bool($arg)) {
$args[] = $arg ? "true" : "false";
} elseif (is_object($arg)) {
$args[] = get_class($arg);
} elseif (is_resource($arg)) {
$args[] = get_resource_type($arg);
} else {
$args[] = $arg;
}
}
$args = join(", ", $args);
}
$ret .= sprintf("#%s %s(%s): %s(%s)\n", $count, isset($trace['file']) ? $trace['file'] : 'unknown file', isset($trace['line']) ? $trace['line'] : 'unknown line', isset($trace['class']) ? $trace['class'] . $trace['type'] . $trace['function'] : $trace['function'], $args);
$count++;
}
return $ret;
}
示例2: __construct
/**
* Class Constructor
*
* @param array|string|resource $streamOrUrl Stream or URL to open as a stream
* @param string|null $mode Mode, only applicable if a URL is given
* @return void
* @throws Zend_Log_Exception
*/
public function __construct($streamOrUrl, $mode = null)
{
// Setting the default
if (null === $mode) {
$mode = 'a';
}
if (is_resource($streamOrUrl)) {
if (get_resource_type($streamOrUrl) != 'stream') {
// require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception('Resource is not a stream');
}
if ($mode != 'a') {
// require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception('Mode cannot be changed on existing streams');
}
$this->_stream = $streamOrUrl;
} else {
if (is_array($streamOrUrl) && isset($streamOrUrl['stream'])) {
$streamOrUrl = $streamOrUrl['stream'];
}
if (!($this->_stream = @fopen($streamOrUrl, $mode, false))) {
// require_once 'Zend/Log/Exception.php';
$msg = "\"{$streamOrUrl}\" cannot be opened with mode \"{$mode}\"";
throw new Zend_Log_Exception($msg);
}
}
$this->_formatter = new Zend_Log_Formatter_Simple();
}
示例3: printParams
public static function printParams($params, $glue = ',')
{
$res = '';
if (count($params)) {
foreach ($params as $val) {
if (is_string($val)) {
$val = sprintf('\'%s\'', $val);
} else {
if (is_int($val) || is_float($val)) {
null;
} else {
if (is_bool($val)) {
$val = $val ? 'true' : 'false';
} else {
if (is_array($val)) {
$val = sprintf('array:%s', json_encode($val, JSON_UNESCAPED_UNICODE));
} else {
if (is_object($val)) {
$val = sprintf('[object]%s:%s', get_class($val), json_encode($val, JSON_UNESCAPED_UNICODE));
} else {
if (is_resource($val)) {
$val = sprintf('[resource]%s', get_resource_type($val));
} else {
$val = 'other';
}
}
}
}
}
}
$res .= $glue . ' ' . strval($val);
}
}
return substr($res, 2);
}
示例4: varToString
private function varToString($var)
{
if (is_object($var)) {
return sprintf('Object(%s)', get_class($var));
}
if (is_array($var)) {
$a = array();
foreach ($var as $k => $v) {
$a[] = sprintf('%s => %s', $k, $this->varToString($v));
}
return sprintf('Array(%s)', implode(', ', $a));
}
if (is_resource($var)) {
return sprintf('Resource(%s)', get_resource_type($var));
}
if (null === $var) {
return 'null';
}
if (false === $var) {
return 'false';
}
if (true === $var) {
return 'true';
}
return (string) $var;
}
示例5: Open
function Open($ArchFile, $UseIncludePath = false)
{
// Open the zip archive
if (!isset($this->Meth8Ok)) {
$this->__construct();
}
// for PHP 4 compatibility
$this->Close();
// close handle and init info
$this->Error = false;
$this->ArchIsNew = false;
$this->ArchIsStream = is_resource($ArchFile) && get_resource_type($ArchFile) == 'stream';
if ($this->ArchIsStream) {
$this->ArchFile = 'from_stream.zip';
$this->ArchHnd = $ArchFile;
} else {
// open the file
$this->ArchFile = $ArchFile;
$this->ArchHnd = fopen($ArchFile, 'rb', $UseIncludePath);
}
$ok = !($this->ArchHnd === false);
if ($ok) {
$ok = $this->CentralDirRead();
}
return $ok;
}
示例6: serializeValue
public static function serializeValue($value)
{
if ($value === null) {
return 'null';
} elseif ($value === false) {
return 'false';
} elseif ($value === true) {
return 'true';
} elseif (is_float($value) && (int) $value == $value) {
return $value . '.0';
} elseif (is_object($value) || gettype($value) == 'object') {
return 'Object ' . get_class($value);
} elseif (is_resource($value)) {
return 'Resource ' . get_resource_type($value);
} elseif (is_array($value)) {
return 'Array of length ' . count($value);
} elseif (is_integer($value)) {
return (int) $value;
} else {
$value = (string) $value;
if (function_exists('mb_convert_encoding')) {
$value = mb_convert_encoding($value, 'UTF-8', 'UTF-8');
}
return $value;
}
}
示例7: emit
public function emit($cycle, $r = null)
{
$writer = $cycle->writer() ? $cycle->writer() : $cycle();
if ($r) {
if (is_callable($r)) {
$r = $r();
}
if (is_resource($r) and get_resource_type($r) == 'stream') {
//flush header
$writer();
$stream = $cycle->response()->getBody()->detach();
stream_copy_to_stream($r, $stream);
$cycle->response()->getBody()->attach($stream);
} elseif (is_array($r) or $r instanceof \Traversable or $r instanceof \Generator) {
foreach ($r as $part) {
$writer($part);
}
} else {
$writer((string) $r);
}
} else {
//flush if not
$writer();
}
}
示例8: spy
function spy($x)
{
switch (1) {
case is_string($x):
return '"' . $x . '"';
case is_numeric($x):
return $x;
case is_null($x):
return 'NULL';
case is_bool($x):
return $x ? 'TRUE' : 'FALSE';
case is_resource($x):
return '(' . get_resource_type($x) . ')' . "{$x}";
case is_object($x):
return get_class($x);
case is_array($x):
break;
case is_scalar($x):
default:
return "{$x}";
}
switch (count($x)) {
case 0:
return '[]';
case 1:
return '[' . spy(array_first_key($x)) . ' => ' . spy(array_pop($x)) . ']';
case 2:
return '[' . spy(array_first_key($x)) . ' => ' . spy(array_shift($x)) . ', ' . spy(array_last_key($x)) . ' => ' . spy(array_pop($x)) . ']';
default:
return '[' . spy(array_first_key($x)) . ' => ' . spy(array_shift($x)) . ', ..., ' . spy(array_last_key($x)) . ' => ' . spy(array_pop($x)) . ']';
}
trigger_error('Something terrible has happened.');
}
示例9: __construct
/**
* Constructor...
*
* @param Resource $result The SQLite result resource
*/
public function __construct($result)
{
if (!is_resource($result) || get_resource_type($result) != 'sqlite result') {
throw new \r8\Exception\Argument(0, "Result Resource", "Must be a SQLite Result resource");
}
$this->result = $result;
}
示例10: __construct
/**
* Creates a new stream.
*
* @param stream $stream
*/
public function __construct($stream)
{
if (!is_resource($stream) || get_resource_type($stream) !== 'stream') {
throw new \RuntimeException(self::class . '::__construct($stream) expects a stream as the first argument!');
}
$this->stream = $stream;
}
示例11: setTimeout
public function setTimeout($timeout)
{
$this->options['timeout'] = $timeout;
if ($this->socket && get_resource_type($this->socket) === 'stream') {
stream_set_timeout($this->socket, $timeout);
}
}
示例12: __construct
public function __construct($value, $class = '')
{
$this->class = $class;
$this->value = $value;
switch (gettype($value)) {
case 'object':
$this->type = self::TYPE_OBJECT;
$this->class = get_class($value);
$this->cut = -1;
break;
case 'array':
$this->type = self::TYPE_ARRAY;
$this->class = self::ARRAY_ASSOC;
$this->cut = $this->value = count($value);
break;
case 'resource':
case 'unknown type':
$this->type = self::TYPE_RESOURCE;
$this->class = @get_resource_type($value);
$this->cut = -1;
break;
case 'string':
if ('' === $class) {
$this->type = self::TYPE_STRING;
$this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY;
$this->cut = self::STRING_BINARY === $this->class ? strlen($value) : (function_exists('iconv_strlen') ? iconv_strlen($value, 'UTF-8') : -1);
$this->value = '';
}
break;
}
}
示例13: __construct
/**
* The constructor
* @param resource $socket a valid socket resource
* @throws \InvalidArgumentException
*/
public function __construct($socket)
{
if (!is_resource($socket) && strtolower(@get_resource_type($socket)) != 'socket') {
throw new \InvalidArgumentException('Socket resource is required!');
}
$this->socket = $socket;
}
示例14: __construct
function __construct()
{
/**
* The constructor can either be called with an existing database handle
* or a set of four parameters to use with mysqli_[p]connect():
*
* $db = new DB_MySQL($my_existing_mysqli_link_handle);
*
* or
*
* $db = new DB_MySQL("localhost", "my_db", "db_user", "db_password");
*
*/
switch (func_num_args()) {
case 1:
$h = func_get_arg(0);
// Make sure what we got really is a mysql link
assert(is_resource($h));
$t = get_resource_type($h);
if ($t == "mysql link") {
$this->isPersistent = false;
} elseif ($t == "mysql link persistent") {
$this->isPersistent = true;
} else {
trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() Passed handle isn't a mysql connection - it's a {$t} resource!", E_USER_ERROR);
}
$this->Handle = $t;
return;
case 4:
list($this->Server, $this->Database, $this->Username, $this->Password) = func_get_args();
break;
default:
trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() called with " . func_num_args() . " arguments - it should be called with either 1 (a mysql connection handle) or 4 (the server, db_name, user, and password to connect with)", E_USER_ERROR);
}
}
示例15: is_ref
public static function is_ref(&$arg1, &$arg2)
{
if (!self::is_same($arg1, $arg2)) {
return false;
}
$same = false;
if (is_array($arg1)) {
do {
$key = uniqid("is_ref_", true);
} while (array_key_exists($key, $arg1));
if (array_key_exists($key, $arg2)) {
return false;
}
$data = uniqid('is_ref_data_', true);
$arg1[$key] =& $data;
if (array_key_exists($key, $arg2)) {
if ($arg2[$key] === $data) {
$same = true;
}
}
unset($arg1[$key]);
} elseif (is_object($arg1)) {
if (get_class($arg1) !== get_class($arg2)) {
return false;
}
$obj1 = array_keys(get_object_vars($arg1));
$obj2 = array_keys(get_object_vars($arg2));
do {
$key = uniqid('is_ref_', true);
} while (in_array($key, $obj1));
if (in_array($key, $obj2)) {
return false;
}
$data = uniqid('is_ref_data_', true);
$arg1->{$key} =& $data;
if (isset($arg2->{$key})) {
if ($arg2->{$key} === $data) {
$same = true;
}
}
unset($arg1->{$key});
} elseif (is_resource($arg1)) {
if (get_resource_type($arg1) !== get_resource_type($arg2)) {
return false;
}
return (string) $arg1 === (string) $arg2;
} else {
if ($arg1 !== $arg2) {
return false;
}
do {
$key = uniqid('is_ref_', true);
} while ($key === $arg1);
$tmp = $arg1;
$arg1 = $key;
$same = $arg1 === $arg2;
$arg1 = $tmp;
}
return $same;
}