PHP Class arguments in functions

arguments, class, function, php

Solution

You need to set the class property using the $this keyword.

class company {

   var $name;

   function __construct($name) {
      echo $name;
      $this->name = $name;
   }

   function name() {
      echo $this->name;
   }
}

$comp = new company('TheNameOfSomething');
$comp->name();

Problem

I'm having trouble using an argument from my class in one of that class's functions. I have a class called company: ``` class company { var $name; function __construct($name) { echo $name; } function name() { echo $name; } } $comp = new company('TheNameOfSomething'); $comp->name(); ``` When I instantiate it (second to last line), the construct magic method works fine, and echos out "TheNameOfSomething." However, when I call the name() function, I get nothing. What am I doing wrong? Any help is greatly appreciated. If you need any other info, just ask! Thanks -Giles http://gilesvangruisen.com/

Original source