Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17043 > unrolled thread

Re: print out variable name as well as its content

Started bysendtorobert@gmail.com
First post2016-09-09 08:23 -0700
Last post2016-09-09 17:57 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.php

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: print out variable name as well as its content sendtorobert@gmail.com - 2016-09-09 08:23 -0700
    Re: print out variable name as well as its content "R.Wieser" <address@not.available> - 2016-09-09 17:57 +0200

#17043 — Re: print out variable name as well as its content

Fromsendtorobert@gmail.com
Date2016-09-09 08:23 -0700
SubjectRe: print out variable name as well as its content
Message-ID<3aa14ac8-7d76-4fe2-bc89-dbda54846637@googlegroups.com>
On Thursday, October 18, 2007 at 8:03:54 PM UTC-4, Rik Wasmus wrote:
> On Fri, 19 Oct 2007 01:52:42 +0200, Summercool <Summercoolness@gmail.com>  
> wrote:
> 
> > I wonder in PHP, can you have a function like
> >
> >   print_debug($foo);
> >
> > and it will print out:
> >
> > $foo is:
> > 3
> >
> > that is, it will print out, most importantly, the variable name, as
> > well as its content.
> >
> 
> No, as it's name should be of utter unimportance.
> 
> (Somewhere in this group there's been given a 'solution' for this about a  
> year ago I think. It involved using debug_backtrace(), fopen()ing the file  
> and reading/parsing the line indicated in that array. Not anything you  
> should want to do.)
> 
> As said, the variable name should be of no importance. If you're trying to  
> pinpoint changes in your script you can either use __FILE__ & __LINE__  
> along with the output, of use the debug_backtrace() mentioned earlier in a  
> function to output the file & line it was called.
> -- 
> Rik Wasmus

This may be true in most cases, but I'm running into this situation now.  It's a situation whereby I'm grabbing field names from a database and assigning them to a variable $X.  I need to see as I pass through each field if it's giving the $X variable the name of each field as it's variable name.  I'm trying to dynamically create variables based on those field names.  I've done this, I think...but I need to test it.  Simply doing an ECHO '$X'; only shows me "$X," which means what?...that it's not working or that it's simply treating ECHO '$X' as an explicit vs the actual variable name?

[toc] | [next] | [standalone]


#17044

From"R.Wieser" <address@not.available>
Date2016-09-09 17:57 +0200
Message-ID<57d2db08$0$881$e4fe514c@news.xs4all.nl>
In reply to#17043
Robert (if thats your name),

First off, that message you're responding to is 9 *years* old.   I don't
think that Rik will still be waiting for an answer (this "lets 'necrobump' "
seems to be a Google forums problem only).

Second: your question has got very little (read: nothing) to do with his
problem.

So, next time when you have a problem do not tack it on a ( very) old
message with a different problem, but post it on its own

As for your problem ?

#1: $X is *NOT* text.  So, why are you encolosing it in (single)quotes ?

#2: AFAIK single-quotes around a string prohibit PHP from interpreting its
contents and replacing eventually embedded PHP variables with their
contents.
So, if you *have* to use quotes (which you, in this example, do not), use
double-instead of single-quotes.

Regards,
Rudy Wieser


-- Origional message:
<sendtorobert@gmail.com> schreef in berichtnieuws
3aa14ac8-7d76-4fe2-bc89-dbda54846637@googlegroups.com...
On Thursday, October 18, 2007 at 8:03:54 PM UTC-4, Rik Wasmus wrote:
> On Fri, 19 Oct 2007 01:52:42 +0200, Summercool <Summercoolness@gmail.com>
> wrote:
>
> > I wonder in PHP, can you have a function like
> >
> >   print_debug($foo);
> >
> > and it will print out:
> >
> > $foo is:
> > 3
> >
> > that is, it will print out, most importantly, the variable name, as
> > well as its content.
> >
>
> No, as it's name should be of utter unimportance.
>
> (Somewhere in this group there's been given a 'solution' for this about a
> year ago I think. It involved using debug_backtrace(), fopen()ing the file
> and reading/parsing the line indicated in that array. Not anything you
> should want to do.)
>
> As said, the variable name should be of no importance. If you're trying to
> pinpoint changes in your script you can either use __FILE__ & __LINE__
> along with the output, of use the debug_backtrace() mentioned earlier in a
> function to output the file & line it was called.
> --
> Rik Wasmus

This may be true in most cases, but I'm running into this situation now.
It's a situation whereby I'm grabbing field names from a database and
assigning them to a variable $X.  I need to see as I pass through each field
if it's giving the $X variable the name of each field as it's variable name.
I'm trying to dynamically create variables based on those field names.  I've
done this, I think...but I need to test it.  Simply doing an ECHO '$X'; only
shows me "$X," which means what?...that it's not working or that it's simply
treating ECHO '$X' as an explicit vs the actual variable name?


[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web