Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 307345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:33:01+00:00 2026-05-12T07:33:01+00:00

I’m using someone elses class and that person has defined a function with five

  • 0

I’m using someone elses class and that person has defined a function with five arguments.

in Sentry.php:

function checkLogin($user = '',$pass = '',$group = 10,$goodRedirect = '',$badRedirect = '')

If all five fields are filled in this leads to a login procedure.

Now on the page where he explains how to use this there is a snippet which, according to php.net, doesn’t make sense.

in a page that loads the sentry:

require_once('../system/Sentry.php');
$theSentry = new Sentry();
if(!$theSentry->checkLogin(2)){ header("Location: login.php"); die(); }

which by default should behave as such that it checks if the $group argument is <= 10 (default). In this situation it should be two. If the user checked has a group-variable of <=2 this should enable the person to view the page.

However, this doesn’t work and for a very obvious reason: the php manual states:

Note that when using default
arguments, any defaults should be on
the right side of any non-default
arguments; otherwise, things will not
work as expected.

So the code, according to phpbuilder.com should have no optional ($variable = default_something) field to fill in with a call to the function and it definitely shouldn’t be defined as the third of five arguments.

How can I use the function like this?:

checkLogin(2)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:33:01+00:00Added an answer on May 12, 2026 at 7:33 am

    Default arguments are PHP’s way of dealing with the lack of overloaded functions. In Java you can write this:

    public void login(String username)
    public void login(String username, String password)
    

    In PHP you have to solve it like this:

    function login($username, $password = '')
    

    This way $username is mandatory and $password is optional. While this may be convenient, it isn’t always. In your example there are a log of arguments and they are all optional. A clean solution for this would be to make 1 function that does the work and add ‘convenience’ methods to make the interface cleaner.

    So add:

    function checkLoginGroup($group = 10) {
      $this->checkLogin('', '', $group);
    }
    

    It simply calls the function that already exists, but it allows for a cleaner interface, just call:

    $theSentry->checkLoginGroup(2);
    

    It’s even neater to make the provided method private (or protected, depending on your needs) and create public ‘convience’ methods so you can hide the implementation details.

    However, if you can not or don’t want to change the original class, you might be able to create a subclass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 193k
  • Answers 193k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer One possibility: instead of calling a web role, just load… May 12, 2026 at 6:31 pm
  • Editorial Team
    Editorial Team added an answer You should look at using a "view model". You basically… May 12, 2026 at 6:31 pm
  • Editorial Team
    Editorial Team added an answer You could try: $("selector").removeAttr("style"); but my question is: why do… May 12, 2026 at 6:31 pm

Related Questions

In order to apply a triggered animation to all ToolTip s in my app,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.