php foreach 添加属性,php 为什么能 foreache 到一个对象的受保护属性

10

2015-08-31 17:51:55 +08:00

@haiyang416 @freefcw @lijinma @solupro

首先是返回这个对象的方法。

```

/**

* Fetches all rows.

*

* @param string|array $where OPTIONAL An SQL WHERE clause

* @param string|array $order OPTIONAL An SQL ORDER clause.

* @param int $count OPTIONAL An SQL LIMIT count.

* @param int $offset OPTIONAL An SQL LIMIT offset.

* @return APP_Db_Table_Rowset_Abstract object

*/

public function fetchAll ($where = null, $order = null, $count = null, $offset = null )

{

$table = $this->_schema . '.' . $this->_db->quoteIdentifier ($this->_name );

$select = "SELECT * FROM $table";

// if ($where !== null )

if ($where !== null && !empty ($where ))

{

$select .= ' WHERE ' . $this->_where ($where );

}

if ($order !== null && !empty ($order ))

{

$select .= ' ORDER BY ' . $this->_order ($order );

}

if ($count !== null || $offset !== null )

{

$select = $select . $this->_db->limit ($count, $offset );

// $select = $this->_db->limit ($select, $count, $offset );

}

$data = $this->_fetch ($select );

require_once 'APP/Loader.php';

APP_Loader::loadClass ($this->_rowsetClass );

return new $this->_rowsetClass ($data );

}

```

然后是包含进来的 APP/Loader.php

```

/**

* @category APP

* @package APP_Loader

* @version $Id: Loader.php v1.0 2009-2-25 0:08:04 tomsui $

*/

class APP_Loader

{

/**

* Load a class

*

* Load a APP class file. If the class already exists in memory, return

* directly.

*

* @static

* @param string $class String name of the class to load.

* @param array $config OPTIONAL; an array with adapter parameters.

* @return void

* @throws APP_Exception

*/

public static function loadClass ($class )

{

if (class_exists ($class, false ) || interface_exists ($class, false )) {

return;

}

$file = str_replace ('_', DIRECTORY_SEPARATOR, $class ) . '.php';

self::_securityCheck ($file );

require ($file ) ;

}

/**

* Autoload switch

*

* if switch opens, APP class can be used without loading previously

*

* @static

* @param boolean $use to set wheather Autoload switcher in use or not.

* @return void

*/

public static function Autoload ($use = true )

{

if ($use ){

spl_autoload_register (array ('APP_Loader', 'loadClass'));

}else{

spl_autoload_unregister (array ('APP_Loader', 'loadClass'));

}

}

/**

* Security Check

*

* File name of APP classs can just contain alpha,digits,backslash (/),

* slash (\),underline (_),period (.) and dash (-). If contains other irregular

* charactor, an APP_Exception is thrown.

*

* @static

* @param boolean $filename the filename string to be check.

* @return void

* @throws APP_Exception

*/

protected static function _securityCheck ($filename )

{

if (preg_match ('/[^a-z0-9\\/\\\\_.-]/i', $filename )) {

require_once 'APP/Exception.php';

throw new APP_Exception ('Security check: Illegal character in filename');

}

}

}

```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值