sensorario
(Sensorario)
February 3, 2011, 5:58pm
1
On My PC I have tried to modify CActiveRecord::model() because there is strange behavior in my website when is on server that is in production:
(only var_dump were added)
public static function model($className=__CLASS__) {
if (isset(self::$_models[$className])) {
return self::$_models[$className];
} else {
$model = self::$_models[$className] = new $className(null);
var_dump($model);
$model->_md = new CActiveRecordMetaData($model);
$model->attachBehaviors($model->behaviors());
return $model;
}
}
This is what I see on my PC
ubuntu 10.04
php 5.2.3
object(Automobili)#20 (13) {
["immagine"]=> NULL
["_md":"CActiveRecord":private]=> NULL
["_new":"CActiveRecord":private]=> bool(false)
["_attributes":"CActiveRecord":private]=> array(0) { }
["_related":"CActiveRecord":private]=> array(0) { }
["_c":"CActiveRecord":private]=> NULL
["_pk":"CActiveRecord":private]=> NULL
["_alias":"CActiveRecord":private]=> string(1) "t"
["_errors":"CModel":private]=> array(0) { }
["_validators":"CModel":private]=> NULL
["_scenario":"CModel":private]=> string(0) ""
["_e":"CComponent":private]=> NULL
["_m":"CComponent":private]=> NULL }
This is what I see online
ubuntu 6.06
php 5.1.2
object(Automobili)#19 (13) {
["immagine"]=> NULL
["_md:private"]=> NULL
["_new:private"]=> bool(false)
["_attributes:private"]=> array(0) { }
["_related:private"]=> array(0) { }
["_c:private"]=> NULL
["_pk:private"]=> NULL
["_alias:private"]=> string(1) "t"
["_errors:private"]=> array(0) { }
["_validators:private"]=> NULL
["_scenario:private"]=> string(0) ""
["_e:private"]=> NULL
["_m:private"]=> NULL }
Any suggestion? php 5.1.2 is the up to date php version for 6.06. Upgrade maybe is a risk.
samdark
(Alexander Makarov)
February 3, 2011, 6:57pm
2
What’s wrong with the output? Do you have anything actually broken?
sensorario
(Sensorario)
February 4, 2011, 8:28am
3
In My website when I load model and do var_dump($model) I see different things.
When I try to upload images, file name is lost in the void. File saved is "Object# 44" and not "foo.jpg". The object contains dimensions, extension … but no file name. So I tried to analyze code. On my PC I alwais see the type of vars of models. In upload, I see the file is CUploadedFile but online I dont see that. I think this makes some trouble in code. Yii or some classes dont see a property … so generate an exception.
When I see different output dumping model, I get worried.
samdark
(Alexander Makarov)
February 4, 2011, 12:09pm
4
As you can see, values from your dumps are exactly the same. What’s different is output format. There were some fixes for var_dump between 5.1.2 and 5.2.3: http://php.net/ChangeLog-5.php so maybe dump format was changed.
So it’s better to start from the start and show your controller, view and model.
sensorario
(Sensorario)
February 4, 2011, 2:26pm
5
I know! I’ve read all the stuff of var_dump in that page. Controller is ok. Now I’ve create another Virtual Machine with same server and php version. Generates the same error. So, now I try to upgrade PHP. If mistakes get out, the reasons of all the stuff are that CUploadedFile do not work with php 5.1.2. But the reason of why … is out of my understanding.
samdark
(Alexander Makarov)
February 4, 2011, 2:47pm
6
Can’t tell this either since I don’t have your code.
mdomba
(Maurizio Domba Cerin)
February 4, 2011, 3:03pm
7
I think I got what is wrong here…
CUploadedFile uses a magic method __toString()…
Checking this documentation - http://php.net/manua …oop5.magic.php
It say that in PHP before 5.2.0 that method worked only for echo() or print()
mdomba
(Maurizio Domba Cerin)
February 4, 2011, 5:03pm
9
Can’t… I don’t have the 5.1.x PHP version…
sensoorario posted the code in the Italian section, you can see it here - http://www.yiiframework.com/forum/index.php?/topic/15941-model-diversi-stesso-codice-ma-versione-di-php/page__view__findpost__p__79327
And note that on the above posted PHP doc. link… that info is not a user contributed content… but official PHP documentation
here is the quote:
It is worth noting that before PHP 5.2.0 the __toString method was only called when it was directly combined with echo() or print(). Since PHP 5.2.0, it is called in any string context (e.g. in printf() with %s modifier) but not in other types contexts (e.g. with %d modifier). Since PHP 5.2.0, converting objects without __toString method to string would cause E_RECOVERABLE_ERROR .
samdark
(Alexander Makarov)
February 4, 2011, 6:14pm
10
I see. Yes, it’s PHP 5.1 limitation and you should write code in the way mdomba posted in Italian section.
Is
$img=CUploadedFile::getInstance(...)
usage described in the guide or wiki?
mdomba
(Maurizio Domba Cerin)
February 4, 2011, 7:01pm
11
I really don’t know where I got that (could be from an forum post example, but it was a long time ago that I needed that)…
that is the way I’m used it in one project, did not need it afterwards…
so the solution is to use a temporary variable to hold the CUploadedFile instance like:
$img=CUploadFile::getInstance(...);
and when a filename is needed:
$model->filename=$img->name;