ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int type TSRMLS_DC) /* {{{ */
{
zval *retval;
zend_class_entry *ce;
switch (type) {
case IS_STRING:
ce = Z_OBJCE_P(readobj);
// 如果用户的class中定义了__toString,则尝试调用
if (ce->__tostring &&
(zend_call_method_with_0_params(&readobj, ce, &ce->__tostring, "__tostring", &retval) || EG(exception))) {
……
}
return FAILURE;
……
}
return FAILURE;
}
从上述具体实现来看,默认的cast_object就是去寻找class中的__tostring方法然后调用…
回到刚开始的例子,define(‘foo', $a) ,由于$a是A的实例,并且class A中定义了__toString,因此实际上foo常量就等于toString的返回值bar。
...
// 打开zip文件
$my_zip = zip_open("article.zip");
if(is_resource($my_zip))
{
echo("已成功打开zip文件。");
// 关闭z
...2> $this->result 是资源吧? 判断是否为资源应用 is_resource 函数 if(! $this->result || ! is_resource($this->result)) $this->result 是资源吧? 判断是否为资源应用 is
...每字段以\t分隔,每行以\n结尾
$fp = fopen($inputfile,'r');
if(!is_resource($fp)){
echo "打开文件".$inputfile."失败,分析日志程序终止";
exit(1);
}
while(!feof($fp)){
...限制 is_real -- is_float() 的别名 is_resource -- 检测变量是否为资源类型bool is_resource ( mixed var )如果给出的参数 var 是 resource 类型,is_resource() 返回 TRUE,否则返回
...tion fetch_array()
{
if (! is_resource($this->result)) {
throw new Exception(Query not executed.);
...间".date('Y-m-d H:i:s')."\n";
$resource = popen($command,'r');
if(is_resource($resource)){
$success++;
pclose($resource);//下
...key)); if (isset($lock[$key])) { if (is_resource($lock[$key][0])) fclose($lock[$key][0]); unlink($lock[$ke
...ean
*/
function changeSize($width, $height = -1) {
if(!is_resource($this->imageResource)) {
exit('不能改变图片的尺寸,可能是你没有
...ept an HTTP request */ foreach ($write as $w) { if(!is_resource($w))continue; $id = array_search($w, $sockets); fwrite($w, "GET / HTTP/1
... }
return $Id;
}
function _Dbs_Close() {
if (is_resource($this->Id)) {
return @mysql_close($this->Id);