Jump to content

dynamic attribute; eval a string; attribute of attribute


tivrfoa

Recommended Posts

hey folks!

 

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

class A {
public $aProperty;
}

class B {

private $a;

function __construct() {
	$this->a = new A();
	$this->a->aProperty = 'A property';
}

function get($attribute) {
	return $this->$attribute;
}
}

$b = new B();
echo $b->get('a')->aProperty; // work
echo $b->get('a->aProperty'); // doesn't work 

echo '<p>the end</p>';

?>

 

How can I make the code that doesn't work work?

 

Thank you!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.