Lutianna
Lutianna

Reputation: 543

PHP: how to used a class function?

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

Answers (2)

Grokify
Grokify

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

gabo
gabo

Reputation: 1696

try

$test = new testingm($_GET['n']);

Upvotes: 1

Related Questions