#32155 [NEW]: Add Object cast support
From: anferr at mecon dot gov dot ar
Operating system: Any
PHP version: Irrelevant
PHP Bug Type: Feature/Change Request
Bug description: Add Object cast support
Description:
------------
It'll be very useful to add the ability to cast an object to a parent
class.
A simple example could be security: having a base class with attributes,
is extended by another that can do CRUD operations on DB. When passing to
VIEW layer (according to MVC), just do a cast to base object, and CRUD
actions will be disabled.
Reproduce code:
---------------
class Person {
protected $age;
function getAge() { return $this->age; }
function setAge($age) {$this->age = $age; }
}
class PersonDB extends person {
function load($id) {
// SQL execution
$this->setAge($resultSet->age);
}
}
in Model layer:
$objPersonDB = new PersonDB();
$objPersonDB->load($id);
in Controller layer, sends $person to View layer:
$person = (Person)$objPersonDB;
Expected result:
----------------
if I call, in View layer:
$person->load(5);
must raise an error
Actual result:
--------------
cast do nothing, method is invoked.
--
Edit bug report at http://bugs.php.net/?id=32155&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32155&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32155&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32155&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=32155&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=32155&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=32155&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=32155&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=32155&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=32155&r=support
Expected behavior: http://bugs.php.net/fix.php?id=32155&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=32155&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=32155&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=32155&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32155&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=32155&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=32155&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=32155&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=32155&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=32155&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=32155&r=mysqlcfg
Thread (1 message)
- anferr at mecon dot gov dot ar