Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

<?PEE8CHPEE?>

Name: Anonymous 2007-06-14 13:12 ID:VJC/zrET

/prog/, I have a PHP class, objectTable, and I want this class to be able to name itself based on its variable name, i.e.

$myTable = new objectTable();

print_r( $myTable );
/* should return something like...

objectTable( [name]=>myTable ...)

*/

Any suggestions?

Name: Anonymous 2007-06-14 13:45 ID:Heaven

No. What you're trying to do is unbelievably stupid even for a PHP programmer.

Go read SICP or something.

Name: Anonymous 2007-06-14 18:46 ID:VJC/zrET

>>2
Ok, please discuss why this is stupid

Name: Anonymous 2007-06-14 18:54 ID:R2jcXThw

what does print_r does?

Name: Anonymous 2007-06-14 18:54 ID:R2jcXThw

>>4
disregard that i suck cocks.
what does print_r?

Name: Anonymous 2007-06-15 4:18 ID:uVq2/jlm

>>1
Why would you want that? Variables are just references to objects in memory. All objects are anonymous; names only exist for variables which reference them. Tell me what are you trying to do, and I'll tell you why it's wrong.

>>4
It's similar to Python's pprint. It prints something in a nice way, and it's useful to display dictionaries for debugging. Objects are printed like dictionaries, using their properties.

Name: Anonymous 2007-06-15 4:24 ID:tzFnpbeJ

>>4
>>5
Instead of writing these two posts you could have typed php.net/print_r 4.9 times.

Name: Anonymous 2007-06-15 6:20 ID:Z4S5hSaV

var_dump() > print_r

Name: Anonymous 2007-06-15 9:15 ID:MLOdOG7h

WAHT DOES PRINTR DO?????????????????????????

Name: Anonymous 2007-06-15 9:56 ID:x2/5Cwbe

you should write something like

print("myTable");
print_r( $myTable );

Name: Anonymous 2007-06-15 10:28 ID:uVq2/jlm

>>8
var_export > var_dump

Name: Anonymous 2007-06-15 13:09 ID:l104phdq

Does this help?

% cat x.php
<?
$foo = "hello";
$bar = "foo";
print ${$bar};
?>

% php x.php
hello

Name: Anonymous 2007-06-15 14:56 ID:PTv0c4s8

>>12
nope, can't do that to objects

Name: Anonymous 2007-06-15 21:49 ID:2flRpAxi

mmm
can't you do a function similar to print_r, called something like

print_r2("myTable")

which would assign to the variable myTable the name myTable, then print it out with print_r ?

Name: Anonymous 2007-06-16 9:26 ID:PUlDQAHz

Sure you can, although I'm not sure if you get what I'm saying. I'm not handing you code on a plate, I'm pointing out that it's possible to have the name of a variable and use that to get the value of a variable, so you don't need to use the name twice in something like dumpFunc("foo", $foo) which seems to be what you're trying to avoid.

% cat x.php
<?

class Foo {
  function Foo() {
    $this->value = 42;
  }
  function get() {
    return $this->value;
  }
}

$obj = new Foo();
$name = "obj";

print ${$name}->get();

?>

% php x.php
42

Name: Anonymous 2009-01-14 14:04

Turing

Don't change these.
Name: Email:
Entire Thread Thread List