I have very strong basic in Java, and when comes to PHP I got some problem with the OOP.
Please take a look at this two classes below:
Contacts.php
<?php
public class Contacts {
}
?>
UnitTest.php
<?php
require_once 'PHPUnit/Framework.php';
include 'Contacts.php';
class UnitTest extends PHPUnit_Framework_TestCase {
public function testRead() {
$temp = new Contacts();
}
}
?>
When I trying to test the UnitTest.php
using phpunit
I got this error message:
PHP Parse error: syntax error, unexpected T_PUBLIC in
/home/crazenezz/Projects/PHP/Demo/Class/Contacts.php on line 3
And after trial and error I remove the public
modifier of Contacts
class, and the test become success without error.
Contacts.php (After remove the public
modifier)
<?php
class Contacts {
}
?>
Can anyone explain why in PHP I cannot use the public
as modifier of a class
?