I am a bit new to php. I am trying to access an objects data members with a variable name. Here is a quick example to demonstrate my problem:
Code: Select all
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$testme = new Test();
$testme->printTest("test2");
class Test
{
public $example = array("test1"=>1, "test2"=>2, "test3"=>3);
function printTest($testNumber)
{
echo $this->$testNumber;
}
}
?>
My goal is to have the above print out 2, but instead it prints out
Code: Select all
Notice: Undefined property: Test::$test2