本文整理匯總了PHP中is_resource函數的典型用法代碼示例。如果您正苦於以下問題:PHP is_resource函數的具體用法?PHP is_resource怎麽用?PHP is_resource使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了is_resource函數的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: createOutputFile
public function createOutputFile()
{
if (!is_resource($this->getFileStream())) {
$this->setFileStream(fopen($this->createFileName(), "w+"));
fwrite($this->getFileStream(), $this->header());
}
}
示例3: obtenerArreglo
public function obtenerArreglo($result)
{
if (!is_resource($result)) {
return false;
}
return pg_fetch_array($result);
}
示例4: testOpeningFileWorks
public function testOpeningFileWorks()
{
$this->assertFalse($this->instance->fileExists('testfile'));
$this->instance->setFileContents('testfile', 'mmmmm plastic');
$this->assertTrue($this->instance->fileExists('testfile'));
$this->assertTrue(is_resource($this->instance->openFile('testfile')));
}
示例5: process
/**
* Process
*
* @param mixed $value
* @param array $options
*
* @return string|null
*/
public function process($value, array $options = array())
{
if ($value === null) {
return;
}
if (!class_exists('\\libphonenumber\\PhoneNumberUtil')) {
throw new \RuntimeException('Library for phone checking not found');
}
if (is_object($value) || is_resource($value) || is_array($value)) {
$this->throwException($options, 'error');
}
try {
$phone = $this->getPhone($value, $options, $is_toll_free);
} catch (\libphonenumber\NumberParseException $e) {
$this->throwException($options, 'error');
}
$util = \libphonenumber\PhoneNumberUtil::getInstance();
if (!$util->isValidNumber($phone)) {
$this->throwException($options, 'error');
}
if ($is_toll_free) {
return $phone->getNationalNumber();
}
return (string) $util->format($phone, $this->getDefaultPhoneFormat($options));
}
示例6: 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;
}
示例7: listCertificates
/**
* Returns all certificates trusted by the user
*
* @return \OCP\ICertificate[]
*/
public function listCertificates()
{
if (!$this->config->getSystemValue('installed', false)) {
return array();
}
$path = $this->getPathToCertificates() . 'uploads/';
if (!$this->view->is_dir($path)) {
return array();
}
$result = array();
$handle = $this->view->opendir($path);
if (!is_resource($handle)) {
return array();
}
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..') {
try {
$result[] = new Certificate($this->view->file_get_contents($path . $file), $file);
} catch (\Exception $e) {
}
}
}
closedir($handle);
return $result;
}
示例8: __construct
/**
* Constructor
* @param resource $resource
* @throws \InvalidArgumentException If invalid resource
*/
public function __construct($resource)
{
if (!is_resource($resource)) {
throw new \InvalidArgumentException('Cannot create LogWriter. Invalid resource handle.');
}
$this->resource = $resource;
}
示例9: prepareData
/**
* Serialize the data for storing.
*
* Serializes the given $data to a executable PHP code representation
* string. This works with objects implementing {@link ezcBaseExportable},
* arrays and scalar values (int, bool, float, string). The return value is
* executable PHP code to be stored to disk. The data can be unserialized
* using the {@link fetchData()} method.
*
* @param mixed $data
* @return string
*
* @throws ezcCacheInvalidDataException
* if the $data can not be serialized (e.g. an object that does not
* implement ezcBaseExportable, a resource, ...).
*/
protected function prepareData($data)
{
if (is_object($data) && !$data instanceof ezcBaseExportable || is_resource($data)) {
throw new ezcCacheInvalidDataException(gettype($data), array('simple', 'array', 'ezcBaseExportable'));
}
return "<?php\nreturn " . var_export($data, true) . ";\n?>\n";
}
示例10: query
public function query($sql)
{
$resource = mysql_query($sql, $this->link);
if ($resource) {
if (is_resource($resource)) {
$i = 0;
$data = array();
while ($result = mysql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
mysql_free_result($resource);
$query = new stdClass();
$query->row = isset($data[0]) ? $data[0] : array();
$query->rows = $data;
$query->num_rows = $i;
unset($data);
return $query;
} else {
return true;
}
} else {
trigger_error('Error: ' . mysql_error($this->link) . '<br />Error No: ' . mysql_errno($this->link) . '<br />' . $sql);
exit;
}
}
示例11: write
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
if (!is_resource($this->stream)) {
if (!$this->url) {
throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().');
}
$this->createDir();
$this->errorMessage = null;
set_error_handler(array($this, 'customErrorHandler'));
$this->stream = fopen($this->url, 'a');
if ($this->filePermission !== null) {
@chmod($this->url, $this->filePermission);
}
restore_error_handler();
if (!is_resource($this->stream)) {
$this->stream = null;
throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: ' . $this->errorMessage, $this->url));
}
}
if ($this->useLocking) {
// ignoring errors here, there's not much we can do about them
flock($this->stream, LOCK_EX);
}
fwrite($this->stream, (string) $record['formatted']);
if ($this->useLocking) {
flock($this->stream, LOCK_UN);
}
}
示例12: __destruct
public function __destruct()
{
if (\is_resource($this->filePointer)) {
$this->writeLocationTable();
\fclose($this->filePointer);
}
}
示例13: 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;
}
}
示例14: realFilesize
function realFilesize($filename)
{
$fp = fopen($filename, 'r');
$return = false;
if (is_resource($fp)) {
if (PHP_INT_SIZE < 8) {
if (0 === fseek($fp, 0, SEEK_END)) {
$return = 0.0;
$step = 0x7fffffff;
while ($step > 0) {
if (0 === fseek($fp, -$step, SEEK_CUR)) {
$return += floatval($step);
} else {
$step >>= 1;
}
}
}
} else {
if (0 === fseek($fp, 0, SEEK_END)) {
$return = ftell($fp);
}
}
}
return $return;
}
示例15: query
private static function query($q, $params = array())
{
if (self::$link === NULL) {
self::connect();
}
self::$numQuerys++;
$q .= self::$order;
$q .= self::$limit;
self::$order = '';
self::$limit = '';
self::$sql = $q;
self::$result = mysql_query($q, self::$link);
if (!self::$result) {
return false;
} else {
if (!is_resource(self::$result)) {
return true;
}
}
$rset = array();
while ($row = mysql_fetch_assoc(self::$result)) {
$rset[] = $row;
}
return $rset;
}