Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » [PHP-DEV] [RFC] Var_export tabbing [RSS Feed]

#1 Jan. 24, 2011 19:14:38

Hannes L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] [RFC] Var_export tabbing


If you're looking into doing something that are both useful and good for
learning C, my suggestion is to hack PHP in some way that makes something
possible (in PHP) that you couldn't simply accomplish by writing a simple
wrapper function or workaround. Making var_export use tabs instead of spaces
is easily accomplished by wrapping it in another function that preg_replaces
starting line spaces with tabs.

Reading your suggestion, I almost get the feeling that you believe the only
reason var_dump doesn't have more arguments (or does this yet) is because
nobody thought about it or had time changing it. Changing built in php
functions is not A Good Thing™ in general. Functions should serve a specific
purpose, not have a gazillion arbitrary arguments for every possible use
case.

For just the purpose of just learning C however, go ahead. Sounds like a
good start.

Hannes

On 24 January 2011 19:26, Michael Morris <dmgx.mich***@*mail.com> wrote:

> I've been trying to think of something that would be a good project to cut
> my teeth on for a first C project in forever and I'd rather work on
> something that might be useful. While cleaning tabbing on a var_export for
> a test class I think I have an idea.
>
> What I'm looking for is two things. One, is this the sort of thing that a
> beginner to C (not a beginning programmer mind you - I've been doing PHP
> scripting for, gosh, 7 years now) can do. If so I'll do this just for the
> experience of it because I need to learn how to prep patches and the
> remainder of the process for more major patches - such as the include style
> I RFC'ed earlier. It looks like if it's going to happen I'll have to learn
> how to do it.
>
> Anyway, var_export takes 2 arguments - the expression to be converted and
> whether to return or echo it. I'd like to add a third, whether to use
> spaces (default) or tabs for indentation
>
> For backwards compatibility null would mean uses spaces, and use 2 per
> indentation. If set to true a tab character would be used.
>
> Thoughts and input appreciated.
>

Offline

#2 Jan. 24, 2011 19:21:58

Michael M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] [RFC] Var_export tabbing


That is the primary purpose. For most datasets str_replace(' ', "\t",
var_export($obj, true)) gets what I want. But this is for exploration of
process. I don't expect it to be committed to the language on a permanent
basis. To be honest, it would be better as a php.ini setting -
export_indentation. The default value would be ' ' and PHP would fall to
that value if it isn't set.

And I'll likely do that as a step two learning thing.

Changing how includes work was my first suggestion and what I'd like to work
on, but that has to come after more elementary things.

On Mon, Jan 24, 2011 at 2:13 PM, Hannes Landeholm <landeh***@*mail.com>wrote:

> If you're looking into doing something that are both useful and good for
> learning C, my suggestion is to hack PHP in some way that makes something
> possible (in PHP) that you couldn't simply accomplish by writing a simple
> wrapper function or workaround. Making var_export use tabs instead of
> spaces
> is easily accomplished by wrapping it in another function that
> preg_replaces
> starting line spaces with tabs.
>
> Reading your suggestion, I almost get the feeling that you believe the only
> reason var_dump doesn't have more arguments (or does this yet) is because
> nobody thought about it or had time changing it. Changing built in php
> functions is not A Good Thing™ in general. Functions should serve a
> specific
> purpose, not have a gazillion arbitrary arguments for every possible use
> case.
>
> For just the purpose of just learning C however, go ahead. Sounds like a
> good start.
>
> Hannes
>
> On 24 January 2011 19:26, Michael Morris <dmgx.mich***@*mail.com> wrote:
>
> > I've been trying to think of something that would be a good project to
> cut
> > my teeth on for a first C project in forever and I'd rather work on
> > something that might be useful. While cleaning tabbing on a var_export
> for
> > a test class I think I have an idea.
> >
> > What I'm looking for is two things. One, is this the sort of thing that a
> > beginner to C (not a beginning programmer mind you - I've been doing PHP
> > scripting for, gosh, 7 years now) can do. If so I'll do this just for
> the
> > experience of it because I need to learn how to prep patches and the
> > remainder of the process for more major patches - such as the include
> style
> > I RFC'ed earlier. It looks like if it's going to happen I'll have to
> learn
> > how to do it.
> >
> > Anyway, var_export takes 2 arguments - the expression to be converted and
> > whether to return or echo it. I'd like to add a third, whether to use
> > spaces (default) or tabs for indentation
> >
> > For backwards compatibility null would mean uses spaces, and use 2 per
> > indentation. If set to true a tab character would be used.
> >
> > Thoughts and input appreciated.
> >
>

Offline

#3 Jan. 24, 2011 19:55:11

Johannes S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] [RFC] Var_export tabbing


Hi,

On Mon, 2011-01-24 at 13:26 -0500, Michael Morris wrote:
> Anyway, var_export takes 2 arguments - the expression to be converted and
> whether to return or echo it. I'd like to add a third, whether to use
> spaces (default) or tabs for indentation

While I'm not sure that's really needed:
Why not a string parameter - then one could choose between 2 or 4 spaces
and tabs.
As var_Export is using smart_str this should be quite simple change to
do :-)

> For backwards compatibility null would mean uses spaces, and use 2 per
> indentation. If set to true a tab character would be used.

For BC the the key point is if it is omitted, since not passing a
parameter is different from passing NULL (or any other value)

johannes



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

  • Root
  • » PHP
  • » [PHP-DEV] [RFC] Var_export tabbing [RSS Feed]

Board footer

Moderator control

Enjoy the 13th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support