View Issue Details

IDProjectCategoryView StatusLast Update
0003189OXID eShop (all versions)4.07. Source code, Testpublic2012-12-10 13:44
Reportercsimon Assigned To 
PriorityhighSeveritymajorReproducibilityalways
Status resolvedResolutionwon't fix 
Product Version4.5.1 revision 38045 
Summary0003189: __get and __set are not called for every database field
Description__get and __set are not called always for every database field. This is because, if __set is called once, the shop writes the resulting field directly onto the object, which causes that __get is never called if __set was used to set the value.

This makes it hard to only write output filters für database values, without manipulating the object itself.

The solution could be to change oxbase.php line 1185:

$this->$sLongName = $oField;

to something like this:

$this->_aFields[$sLongName] = $oField;

aFields contains every database field of the object as array element, __set should make use of this array and __get should use it too, so that __get is always called and overwritable.

This is a little performance draining, a much cleaner, faster and long time solution would be to implement every database value as an function call.
TagsNo tags attached.
ThemeBoth
BrowserAll
PHP Versionany
Database Versionany

Activities

dainius.bigelis

2011-08-26 14:22

reporter   ~0005126

@Developers: please check from source code side if that's the case and offered solution would solves the problem correctly.

Linas Kukulskis

2011-08-26 15:07

reporter   ~0005128

Reminder sent to: csimon

it is not clear the problem. Can you deeply explain the use case: what you are trying to do and what's go wrong.

csimon

2011-08-26 15:14

reporter   ~0005129

Hi,

For example: You want to filter the short description (without manipulating every template).

Normally, you could hook with a module into oxArticle::__get(), check if $sName is oxshortdesc, filter the data and return the oxField object with the filtered value in this function.

But, because __set and the called method oxBase::_addField are adding the property directly onto $this, php never calls __get again when you are trying to read the property, because __get is only called on properties which are nonexistent.

To make it possible to filter or manipulate the output, it must be avoided to write data directly on the object.

csimon

2011-08-26 15:16

reporter   ~0005130

with "data" i mean properties, of course.

tomas_liubinas

2011-08-29 10:47

reporter   ~0005134

Last edited: 2011-08-29 10:48

"if __set is called once, the shop writes the resulting field directly onto the object, which causes that __get is never called if __set was used to set the value". This is how PHP magic setters and getters are supposed to work. It's not a bug. What you probably need is separate field value getters and setters, which is actually a good idea to be implemented. I'll take care that this request is included to feature request list with higher priority than normal.

Linas Kukulskis

2011-08-29 10:48

reporter   ~0005135

will be added as feature: field value getters and setters