Posted By

pollux on 02/24/09


Tagged

oo


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


Cast a user defined object


 / Published in: PHP
 

URL: http://ch.php.net/manual/en/language.types.type-juggling.php#language.types.typecasting

Usefull for IDE autocompletion

  1. class MyObject {
  2. /**
  3.   * @param MyObject $object
  4.   * @return MyObject
  5.   */
  6. static public function cast(MyObject $object) {
  7. return $object;
  8. }
  9. }
  10.  
  11. $myObject = MyObject::cast($_SESSION["myObject"]);

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: kross on July 26, 2011

Or do it right and use

$session->getMyObject();

You need to login to post a comment.