Jump to content

class method names


Liquid Fire

Recommended Posts

can i name my class method whatever i want without interfering with defined names?  like can i have a method called delete without interfering with the function delete?  I would assume this would be possible but my IDE highlights it different so just want to make sure.

 

I've realised this to, I use PHP Designer 2007 and I was going to name my function fetch, but apparently, there's already one called fetch.  I guess it doesn't matter because you always have to have a referrer when referencing the method.  I mean, let's say I called my function mysql_connect.. I couldn't actually call that method by typing mysql_connect I'd have to take $class->mysql_connect or $this->mysql_connect or even parent::mysql_connect or class::mysql_connect.. I can never reference it without writing something before it.. therefore I think it's safe to do so, it's just the IDE trying to be clever lol. 

Link to comment
https://forums.phpfreaks.com/topic/67094-class-method-names/#findComment-336648
Share on other sites

You can name it (almost) what you want.

 

PHP has reserved some words which you cannot use: http://php.net/reserved

 

That means that

<?php
class Test
{
function echo($string)
{
	echo $string;
}
}

$class = new Test();
$class->echo("test");
?>

will result in:

Parse error: syntax error' date=' unexpected T_ECHO, expecting T_STRING in <file> on line 4[/quote']
Link to comment
https://forums.phpfreaks.com/topic/67094-class-method-names/#findComment-339266
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.