#45375 [NEW]: __object_vars() magic method

2008-06-27 Thread margus dot sipria at gmail dot com
From: margus dot sipria at gmail dot com
Operating system: *
PHP version:  5.2.6
PHP Bug Type: Feature/Change Request
Bug description:  __object_vars() magic method

Description:

When I use __set and __get methods on object i have set data to my object,
and when i wanna get thows methods i would only get public methods that are
non.

Same think is happened when i wanna example transfere Object to json
format, there should be some way that i could get data that i wanna.

This could be very useful example using with Zend Framwork encoding a
Database Table Row
(http://framework.zend.com/manual/en/zend.db.table.row.html) where data is
in private variable.

if not a Core function (that it should be in my opinion) then SPL
interface would be needed.

Reproduce code:
---
class Test {
protected $_data = array();
public function __set($var, $value) {$this-_data[$var] = $value;}   

public function __get($var) {
if (isset($this-_data[$var])) {return $this-_data[$var]; }
trigger_error('Undefined property: ' . __CLASS__ . '::$' . $var,
E_USER_NOTICE);
return null;
}
public function __isset($var) {return isset($this-_data[$var]);}

public function __object_vars() {
return $this-_data;
}
}
$json = new Test();
$json-variable = 'value';

echo json_encode($json);

Expected result:

{variable:value}

Actual result:
--
{}

-- 
Edit bug report at http://bugs.php.net/?id=45375edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=45375r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=45375r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=45375r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=45375r=fixedcvs
Fixed in release: 
http://bugs.php.net/fix.php?id=45375r=alreadyfixed
Need backtrace:   http://bugs.php.net/fix.php?id=45375r=needtrace
Need Reproduce Script:http://bugs.php.net/fix.php?id=45375r=needscript
Try newer version:http://bugs.php.net/fix.php?id=45375r=oldversion
Not developer issue:  http://bugs.php.net/fix.php?id=45375r=support
Expected behavior:http://bugs.php.net/fix.php?id=45375r=notwrong
Not enough info:  
http://bugs.php.net/fix.php?id=45375r=notenoughinfo
Submitted twice:  
http://bugs.php.net/fix.php?id=45375r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=45375r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=45375r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=45375r=dst
IIS Stability:http://bugs.php.net/fix.php?id=45375r=isapi
Install GNU Sed:  http://bugs.php.net/fix.php?id=45375r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=45375r=float
No Zend Extensions:   http://bugs.php.net/fix.php?id=45375r=nozend
MySQL Configuration Error:http://bugs.php.net/fix.php?id=45375r=mysqlcfg



#36696 [Com]: __destruct() is called before serialize() when object stored in session

2008-06-26 Thread margus dot sipria at gmail dot com
 ID:   36696
 Comment by:   margus dot sipria at gmail dot com
 Reported By:  iain at iaindooley dot com
 Status:   Open
 Bug Type: Feature/Change Request
 Operating System: *
 PHP Version:  5.1.2
 Assigned To:  sas
 New Comment:

duplicate with a bug http://bugs.php.net/bug.php?id=33772


Previous Comments:


[2006-03-23 00:27:58] iain at iaindooley dot com

in a garbage collection system, the destructor shouldn't be called on
an object until the last reference to it is destroyed. if i do:

$_SESSION['var'] = new Var();

then a reference to that object that was created should be stored in
the $_SESSION array, and __destruct() should not be called until the
$_SESSION array is destoryed. so clearly the session array must be being
destroyed before the objects within it are serialized, which isn't
right.



[2006-03-22 18:13:41] [EMAIL PROTECTED]

There is nothing wrong with the order here. Temp var gets destroyed as
soon as it is created, while session serialization happens at the end of
the script.



[2006-03-21 23:34:59] iain at iaindooley dot com

i would say that the fact the order of operations changes for a temp
var or an assigned var is a bug.



[2006-03-21 15:47:16] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

When putting objects into session or serializing them manually put the
instantiation result into a variable 1st and then use it.

Ex. $a = new Object();
$_SESSION['obj'] = $a;

Doing so avoids temp var, which gets destroyed right away hence leading
to the wrong order of operations.



[2006-03-20 23:25:16] [EMAIL PROTECTED]

Assigned to the maintainer.



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/36696

-- 
Edit this bug report at http://bugs.php.net/?id=36696edit=1