Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.