Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getRecursiveProperty( $object, $path ) {
- $array = explode( '->', $path );
- if ( empty( $array ) ) {
- return NULL;
- }
- foreach ($array as $i => $property) {
- if( is_numeric( $property ) ) {
- $object = $object[ intval( $property ) ];
- } else {
- if( ! isset( $object->$property ) ) {
- return NULL;
- } elseif( ! is_object( $object->$property ) && ! is_array( $object->$property ) ) {
- return $object->$property;
- } else {
- $object = $object->$property;
- }
- }
- }
- return $object->$property;
- }
- function setRecursiveProperty($object, $path, $value) {
- $array = explode('->', $path);
- foreach ( $array as $i => $property) {
- if( is_numeric( $property ) ) {
- $object = $object[ intval( $property ) ];
- } else {
- if ( ! isset( $object->$property ) ) {
- return FALSE;
- } elseif ( ! is_object( $object->$property ) && ! is_array( $object->$property ) ) {
- $object->$property = $value;
- return TRUE;
- }
- $object = $object->$property;
- }
- }
- return FALSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement