/    Sign up×
Community /Pin to ProfileBookmark

Error in private function.

Hey there, dudes!

I created a private function, but, for some reason, it’s returning a compilation error:

[QUOTE=erro]

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’ in c:Inetpubvhostsneoprintsites.com.brhttpdocsadminclassesadministrador.php on line 57

[/QUOTE]

Line 57 is the first one below:

[code=php]private function encripta($kilus) {
private $secure = explode(‘.’,$kilus);
private $admNome = $_POST[‘senha_administrador’];
return md5($secure[5].$secure[4].base64_encode($secure[2].$admNome.$secure[1]).$secure[3].$secure[0]);
}[/code]

So, what do you think is the problem?

Thanks in advance.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiApr 22.2009 — You wouldn't use private to define the variable scope inside a function - variables defined inside functions are always private unless explicitely declared global. I'm also guessing that this may not be a class method, in which case the private before the function will give you an error too - in short, if this is not a class method remove all instances of the word 'private'.
Copy linkTweet thisAlerts:
@GraniteauthorApr 22.2009 — Ok then, I erased the private in the variables.

Now, this IS a class method. And I know the problem is the 'private' declaration, cause without it, the code works fine. But I want this function to be private! Any suggestion?
Copy linkTweet thisAlerts:
@NogDogApr 22.2009 — Are you using PHP[b]5[/b]?
Copy linkTweet thisAlerts:
@MindzaiApr 22.2009 — ^^^

As NogDog says PHP4 doesn't understand method scope.
Copy linkTweet thisAlerts:
@GraniteauthorApr 22.2009 — But, yeah, I'm using php 5.
Copy linkTweet thisAlerts:
@NogDogApr 22.2009 — This parses fine for me (all I did was delete the occurrences of "private" inside the function and place the function itself within a class definition):
[code=php]
<?php
class test
{
private function encripta($kilus) {
$secure = explode('.',$kilus);
$admNome = $_POST['senha_administrador'];
return md5($secure[5].$secure[4].base64_encode($secure[2].$admNome.$secure[1]).$secure[3].$secure[0]);
}
}
[/code]

If it is not within a class definition, the the "private" declaration for the function must also be removed (and would have no meaning, anyway).
Copy linkTweet thisAlerts:
@GraniteauthorApr 23.2009 — Ha! Solved! ?

The PHP in my local server is version 5. In my web server, however, it was set as 4. Fixed this. Thank you, guys!
×

Success!

Help @Granite spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...