I agree with Christopher when its about proper getters in combination
with magic __get.
Something like "getDATABASEFIELDNAME(oxField::T_RAW)" to access a
property is nicer OOP and can be extended by modules.
Mathias
Am 06.08.2009 um 09:39 schrieb Christopher Simon:
Yes I know, but thats not the actual issue.
$oUser->oxuser__oxcountry = new oxField( 'test', oxField::T_RAW);
$oUser->oxuser__oxcountry will contain a oxfield with 'test', this
field isn't set by the magic getter because it's already existing.
And if i change the property $oUser->oxuser__oxcountryid to an other
country id, $oUser->oxuser__oxcountry will contain the old country
name and it's not updated, like it should.
The main flaw in the current model is, that propertys are set
directly AND magic getters are used for some fields which are set
directly by some line like the one you posted. OXID should use magic
getters, too to assure that such dynamic propertys like
oxuser__oxcountry are updated correctly.
Btw, i don't set the field to "" myself, it happened somewhere in
the oxid efire paypal module and an error occured.
Rimvydas Paskevicius schrieb:
Hello,
You should not use setting object parameters like this:
$oUser->oxuser__oxcountry->value = 'test'
This is why "oxuser__oxcountry" was set to an empty string.
For setting object parameters you should use oxField class
$oUser->oxuser__oxcountry = new oxField( 'test', oxField::T_RAW);
----- Original Message ----- From: "Christopher Simon" <[email protected]
>
To: <[email protected]>
Sent: Wednesday, August 05, 2009 8:16 PM
Subject: [oxid-dev-general] Bad behavior of the ORM
Hi there,
i've noticed that OXID uses magic-getters, but no magic-setters.
I'll explain the problem with an example:
the field "oxuser__oxcountry" is retrieved by the __get function,
if its not already existing. But, if it's set once directly with
an line like this "$oUser->oxuser__oxcountry->value = 'test';" the
magic getter remains uncalled, because the property already exits
on $oUser.
Because of this behavior i had trouble with the efire paypal
module. Somewhere "oxuser__oxcountry" was set to an empty string
(i didn't found the spot yet), and therefore, Paypal recieved no
Country and an error was thrown.
But there is some other misbehavior caused by this: If you once
read oxuser__oxcountry, the metho "getUserCountry()" sets user
country directy on this property. But if user countryId changes in
the meantime, "$oUser->oxuser__oxcountry->value" will remain
untouched because it never gets an update.
In general, working with object propertys directly is very very
dirty. For error prevention in OXID 4 the magic setters should be
utilized as soon as possible. But for OXID 5, i would like to see
OXID to utilize real getters and setters and retrieve values like
this:
$oUser->getCountryName() and set Values like this $oUser-
>setCountryName($value);
This would be more OOP-Style, and more suitable for all module
developers out there, because the "getDatabaseField" methods could
be extended, too.
For dynamic field adding, you could use the "__call" magic method.
_______________________________________________
dev-general mailing list
[email protected]
http://dir.gmane.org/gmane.comp.php.oxid.general
_______________________________________________
dev-general mailing list
[email protected]
http://dir.gmane.org/gmane.comp.php.oxid.general
_______________________________________________
dev-general mailing list
[email protected]
http://dir.gmane.org/gmane.comp.php.oxid.general
_______________________________________________
dev-general mailing list
[email protected]
http://dir.gmane.org/gmane.comp.php.oxid.general