Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

class problem

Status
Not open for further replies.

dogo1984

Programmer
Sep 1, 2002
24
DE
I have got an Problem this is only a test script i write to see what is wrong.

FILE 1:


<?php
class hallo
{
function raus()
{
echo&quot;hi how are you&quot;;
}
}
?>


++------------------------------------------++
++------------------------------------------++


FILE 2:


<?php
include (&quot;hallo.php&quot;);
class test
{
hallo::raus();
}
?>


++-------------------------------------------++
++-------------------------------------------++

if i try it with my browser this is the error text:

Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in C:\ApacheGroup\Apache\hp\php\test1.php on line 6

do somebody now what i have done wrong or where the mistake can be ?

thanks for help !
 
You haven't declared an instance of the class before running the code directly.

<?php
class hallo
{
function raus()
{
echo&quot;hi how are you&quot;;
}
}
?>

--------

<?php
include (&quot;hallo.php&quot;);

$test = new hallo;
$test->raus();

?>

see the website below for a tutorial in creating classes in PHP
 
LittleHavoc:
No, that's not it. Use of the &quot;::&quot; operator to call class functions without object instantiation is legal in PHP version >= 4 (See

dogo1984:
Check to make sure that you don't have odd characters in your whitespace. A lot of web servers, when displaying code, replace normal spaces (hexadecimal 20) with something else (hexadecimal A0). PHP, I've found, doesn't like that (hex A0) character.

Also, I you will not be able to call hallo:raus() from within class &quot;test&quot; like that. Class definitions can only directly contain instantiations of variables and definitions of functions. You are attempting a bare function call inside test. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top