I need to get variable names…
For example:
<?php
class forex{
public $example;
public $example2;
public $example3;
function getNames()
{
return variableNames();
}
}
$class = new forex();
$class->getNames();
?>
I want to get a (like)array like:
array('example','example2','example3');
I wish I tell you.
Ok thank you so much. I have find more useful usage, but I don’t know, maybe it have a problem?
<?php
class Datas {
public $one;
public $two;
public $three;
public function _GetName()
{
return $this;
}
}
$data = new Datas();
print_r($data->_GetName());
?>
Result:
Datas Object ( [one] => [two] => [three] => )
It usage is good or have problems?
…Sure you could do that…but if that is all you wanted
$data = new Datas;
print_r( $data );
No need for the method.
No, your codes have problem. You need to convert your object to array. It need to be below:
$data = new Datas;
$array = (array) $data;
print_r($array);
No, my code does not have a problem.
My code returns the same thing your code above returns.
print_r can’t show object data.
Sorry, but you are mistaken. Do not try and school me in PHP, I’ve been working with it professionally for years. print_r can show object data. Read the documentation: http://www.php.net/manual/en/function.print-r.php
If given a string, integer or float, the value itself will be printed. If given an array, values will be presented in a format that shows keys and elements. Similar notation is used for objects.
Ohh sorry really. I was want to say array_keys can’t use object data. Sorry.