Reputation: 543
I'm quite new and having some trial and test creating a class and objects.
Here's my script:
<?php
class testingm
{
private $t;
public function __construct($file)
{
$this->t = fopen($file, 'rb')
}
}
$test = new testingm;
$s = new file($_GET['n']);
?>
the script says
Warning: Missing argument 1 for testingm::__construct(), called in
how can i provide a value for the $file variable? can someone guide me?
Upvotes: 2
Views: 56
Reputation: 16344
Your constructor method __construct($file)
requires 1 parameter, $file
, which needs to be supplied. The constructor method is called when you instantiate an object using the class with new
.
To do this in your example, pass in the file name when you instantiate your object with new
. For example:
$file = $_GET['n'];
$test = new testingm($file);
The PHP docs have more information on function arguments for passing parameters to methods.
Upvotes: 2