Solved

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

Posted on 2008-09-30
5
2,188 Views
Last Modified: 2012-05-05
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
Comment
Question by:DrDamnit
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:psimation
ID: 22605310
maybe it's the typo on line 28?

echo $this-mac; should be echo $this->mac;?
0
 
LVL 32

Author Comment

by:DrDamnit
ID: 22605672
apparently also an error....fixed, but didn't solve the problem.
0
 
LVL 17

Expert Comment

by:psimation
ID: 22605810
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
 
LVL 32

Author Comment

by:DrDamnit
ID: 22617638
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
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 22756316
try replacing:
public function __construct($f)

with:
public function __construct($f=null)

and see if the notice goes away.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to create a scatter graph with straight lines 6 26
Hacked File Timestamps 4 49
PHP preg_replace code convert to Delphi 14 32
Scope of $_SESSION 17 27
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now