PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Sun Jun 12, 2005 2:05 am
Code: Select all
class class1
{
// Constructor
function class1($Input)
{
$string = $Input;
return $string;
}
// Function
function foo($Input)
{
$string = $Input;
return $string;
}
}
This works.
Code: Select all
$c = new class1($Input);
echo $c->foo();
But I want it like this - any way to get this to work ?
Thanks
Last edited by
anjanesh on Sun Jun 12, 2005 11:14 am, edited 1 time in total.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Sun Jun 12, 2005 8:50 am
The contructor isn't really a function as such. It set's your object up.
In a sense you're trying to echo an object to the page. I don't see the need for it. Is there a reason you want that?
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Sun Jun 12, 2005 10:35 am
Ok. Correct. It returns an object and the object # gets printed.
But what about like this ?
After removing the constructor ofcourse.
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Sun Jun 12, 2005 10:50 am
Code: Select all
<?php
echo class1::foo($input);
?>
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Sun Jun 12, 2005 11:13 am
Thanks for that.
Anyway I did try using scope resolution operator before but as
which gave an error :
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting ',' or ';' in C:\xxx\xxx.php on line n
What the hek was that ?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Jun 12, 2005 11:21 am
should be
as you already know. "::" is the T_AAMAYIM_NEKUTOTAYIM
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Sun Jun 12, 2005 11:32 am
JCart - code2 gives :
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in C:\xxx\xxx.php on line n
protokol's solution
does it.
new is not allowed here