• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2273
  • Last Modified:

__Construct says it is missing an argument, but I passed it -- i swear!

Executing the code below gives me this error:

Warning: Missing argument 1 for maccfg::__construct(), called in /var/www/provision/show-prov.php on line 31 and defined in /var/www/provision/maccfg.class.php on line 12

How to fix?
include('maccfg.class.php');
	
	//Loop throught he directory for config files that relate to phones.
	if($handle = opendir('/srv/tftp'))
	{
		while (false !== ($file = readdir($handle)))
		{
			//Check to see if it is a config file
			$pattern = "/^[a-fA-F0-9]{12}\.cfg/";
			//echo $file;
			if(preg_match($pattern,$file) && $file !== '000000000000.cfg')
			{
				echo "Found config file: " . $file. '<br>';
				$mc = new maccfg($file);
			}
		}
 
===============maccfg.class.php=========================
class maccfg
{
	public $path = '';
	public $mac = '';	
	
	public function __construct($f)
	{
		$this->path ='/srv/tftp/'.$f;
		$this->mac = substr($f,1,12);
		echo $this-mac;
	}

Open in new window

0
DrDamnit
Asked:
DrDamnit
  • 2
  • 2
1 Solution
 
psimationCommented:
maybe it's the typo on line 28?

echo $this-mac; should be echo $this->mac;?
0
 
DrDamnitAuthor Commented:
apparently also an error....fixed, but didn't solve the problem.
0
 
psimationCommented:
Also looks like you are short one terminating } for your If statement starting on line 4.

What is the error you are getting now - maybe also just report your corrected code.
0
 
DrDamnitAuthor Commented:
That's because you only have relevent sections of the code. it is not missing a closing '}'.

Here's the full code:
class maccfg
{
	public $path = '';
	public $mac = '';	
	
	public function __construct($f)
	{
		$this->path ='/srv/tftp/'.$f;
		$this->mac = substr($f,1,12);
		echo $this->mac;
	}
	function get_configs()
	{
		//Use parse mac.cfg to find the config files for this phone.
		$dom = new DOMDocument();
		if(!$xml  = $dom->load($this->path))
		{
			echo "Error while parsing the document!\n";
			exit;
		}
		$de = $dom->documentElement;
		return $de->getattribute('CONFIG_FILES');
	}
 
}

Open in new window

0
 
nizsmoDeveloperCommented:
try replacing:
public function __construct($f)

with:
public function __construct($f=null)

and see if the notice goes away.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now