Suggestion: implement own `var_export` #3232

Closed
klimov-paul opened this Issue Apr 24, 2014 · 7 comments

Comments

Projects
None yet
5 participants
@klimov-paul
Member

klimov-paul commented Apr 24, 2014

I suggest we can create our own analog of the regular var_export() PHP function.
It can be placed at VarDumper helper: VarDumper::export().
At this implementation we can cover array short syntax as well as code indending.
Created method can be used while generatng PHP files like translation files.

@qiangxue qiangxue added this to the 2.0 RC milestone Apr 24, 2014

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Apr 24, 2014

Member

Sounds good to me. How to deal with objects and recursive references?

Member

qiangxue commented Apr 24, 2014

Sounds good to me. How to deal with objects and recursive references?

@nineinchnick

This comment has been minimized.

Show comment
Hide comment
@nineinchnick

nineinchnick Apr 24, 2014

Contributor

Also getting rid of numeric array indexes would be nice.

Contributor

nineinchnick commented Apr 24, 2014

Also getting rid of numeric array indexes would be nice.

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Apr 24, 2014

Member

Sounds good.

Member

samdark commented Apr 24, 2014

Sounds good.

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Apr 24, 2014

Member

How to deal with objects and recursive references

We can convert any arrayable objects to arrays before export.
For any descendant of yii\base\Object we may try convert it into its array configuration:

[
    'class' => 'SomeClass',
    'property1' => '...',
]

As for recursion - I do not know, perhaps throw an exception.

I suppose since we have already created VarDumper::dump(), we can handle this as well.

Member

klimov-paul commented Apr 24, 2014

How to deal with objects and recursive references

We can convert any arrayable objects to arrays before export.
For any descendant of yii\base\Object we may try convert it into its array configuration:

[
    'class' => 'SomeClass',
    'property1' => '...',
]

As for recursion - I do not know, perhaps throw an exception.

I suppose since we have already created VarDumper::dump(), we can handle this as well.

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Apr 24, 2014

Member

I don't think we should turn objects into configuration arrays. If such exported data is loaded later, you will get some data that is different from the original one. Perhaps when seeing an object, we should simply serialize it?

Member

qiangxue commented Apr 24, 2014

I don't think we should turn objects into configuration arrays. If such exported data is loaded later, you will get some data that is different from the original one. Perhaps when seeing an object, we should simply serialize it?

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Apr 24, 2014

Member

Perhaps when seeing an object, we should simply serialize it?

👍

Member

cebe commented Apr 24, 2014

Perhaps when seeing an object, we should simply serialize it?

👍

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Apr 25, 2014

Member

Perhaps when seeing an object, we should simply serialize it?

Makes sense.

Member

klimov-paul commented Apr 25, 2014

Perhaps when seeing an object, we should simply serialize it?

Makes sense.

klimov-paul added a commit to klimov-paul/yii2 that referenced this issue May 9, 2014

qiangxue added a commit that referenced this issue May 20, 2014

tvdavid pushed a commit to tvdavid/yii2 that referenced this issue Jul 24, 2014

tvdavid pushed a commit to tvdavid/yii2 that referenced this issue Jul 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment