Jump to content

[SOLVED] creating a var problem.


xyn

Recommended Posts

hey guys.

Basically i've got a class. but im having a problem setting class vars

using an array... i get a T_VAR error when using $this->$name.

 

my current code is...

Page 1.php

$template = new Class;
$array =array(
  'name' => 'value',
  'name_b' => 'value_2'
);
$template->set_vars($array);

 

and my class is :

class Class {
function assign_vars($array){
	foreach($array as $name => $value){
		return $this->$name = $value;
	}
}
}

Link to comment
Share on other sites

yer i know..

but the $name comes from the array  foreach($array as $name => $value){

 

anyway, ive decuded to use this...

function assign_varname($str){  return $this->varname = $str;

which varname will be changed to what the name actually is... I

was initially hopeing to be able to use an array.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.