Yii Framework Forum: Some mistakes with php version? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Some mistakes with php version? Rate Topic: -----

#1 User is offline   sensorario 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,986
  • Joined: 07-September 10
  • Location:Cesena (Italy)

Posted 03 February 2011 - 12:58 PM

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.
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,338
  • Joined: 17-January 09
  • Location:Russia

Posted 03 February 2011 - 01:57 PM

What's wrong with the output? Do you have anything actually broken?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   sensorario 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,986
  • Joined: 07-September 10
  • Location:Cesena (Italy)

Posted 04 February 2011 - 03:28 AM

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.
0

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,338
  • Joined: 17-January 09
  • Location:Russia

Posted 04 February 2011 - 07:09 AM

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.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#5 User is offline   sensorario 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,986
  • Joined: 07-September 10
  • Location:Cesena (Italy)

Posted 04 February 2011 - 09:26 AM

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.
0

#6 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,338
  • Joined: 17-January 09
  • Location:Russia

Posted 04 February 2011 - 09:47 AM

Can't tell this either since I don't have your code.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#7 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,339
  • Joined: 12-October 09
  • Location:Croatia

Posted 04 February 2011 - 10:03 AM

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()
Find more about me.... btw. Do you know your WAN IP?
0

#8 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,338
  • Joined: 17-January 09
  • Location:Russia

Posted 04 February 2011 - 10:19 AM

mdomba
Can you check it?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#9 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,339
  • Joined: 12-October 09
  • Location:Croatia

Posted 04 February 2011 - 12:03 PM

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.yiiframew...dpost__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:

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.

Find more about me.... btw. Do you know your WAN IP?
0

#10 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,338
  • Joined: 17-January 09
  • Location:Russia

Posted 04 February 2011 - 01:14 PM

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?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#11 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,339
  • Joined: 12-October 09
  • Location:Croatia

Posted 04 February 2011 - 02:01 PM

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;

Find more about me.... btw. Do you know your WAN IP?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users