Reputation:
I am beginning to make classes in php. I have make a reference to my class, but I have the following error:
Fatal error: Class 'NumberCode' not found in C:\...\MasterMind.php on line 14
I have made this code:
<?php
class NumberCode
{
public $Code;
function __construct()
{
print "ok";
}
function makeCode()
{
$counter = 1;
while ($counter < 5)
{
$this->Code = $this->Code . rand(1, 6);
print "ok";
$counter++;
}
}
}
and here is the reference:
<?php
$combination = new NumberCode();
$combination -> makeCode();
$code = $combination -> Code;
print $code
?>
I have try to print some lines code and I have used Fiddler.
Upvotes: 0
Views: 72
Reputation: 239240
The file that uses your class needs to include the file that defines your class. You typically do this with a require
or require_once
statement.
<?php
require_once('path_to_class_file.php');
$combination = new NumberCode();
$combination -> MakeCode();
$code = $combination -> Code;
print $code
?>
Upvotes: 2