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 7218761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:31:35+00:00 2026-05-28T21:31:35+00:00

Helo everyone. I have a class MyClass and a function escape () that can

  • 0

Helo everyone.

I have a class MyClass and a function escape() that can be called as a static class or as an instantiated Object.

MyClass::_escape('..... some string...');

or

$myclass->escape();

What I would like is not to have the underscore on the staic version and for both just have the same function definition. I trie to do.

    class MyClass {

    public $_string = "";

      public function escape($string = null) {

            if($string == null) 
                  return new String(mysql_real_escape_string($this->_string));
            else
                  return new String(mysql_real_escape_string($string)); 

      }


   }

but this function fails by the PHP parser. Is there a way of doing what I attempted to above??

So to summarise, I would like the static call to look like;

   print Myclass::escape('some string');

and the instantiated call to look like;

   print $myobject->escape(); //Which escapes the private variable _string

Hope this was clear.

regards

  • 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-28T21:31:35+00:00Added an answer on May 28, 2026 at 9:31 pm

    There are no parse errors in the code you posted. In fact, it works just as you want it to work, as long as you never pass $string to the escape() method in an object context:

    $foo = new MyClass();
    $foo->_string = 'foo';
    $foo->escape(); // This works.
    MyClass::escape('bar'); // This works, too.
    $foo->escape('baz'); // Don't do this.  It'll escape $string instead of $this->_string.
    

    You could resolve this issue by determining whether or not you’re in a static context within the escape() method, instead of checking for the existence of $string.

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

Sidebar

Related Questions

What am I doing wrong here: class Helo { // main: generate some simple
Helo, I have a two Grid where I have to display some records from
Helo, My question is I have one Stored Procedure in SQL Server that returns
Helo! How can i convert a NSMutableArray object to a NSString ? i try
helo everyone This is a code from a book i have bought. It gives
Helo everyone! I have this live wallpaper in witch I try to show a
Helo. I want to have few instances of webclient that all share all the
How do i roll back changes to an attached object in nhibernate? We have
Helo, I have implemented a chat application using Comet. the request is hang on
Helo, i have the following code which should filter entities. Half of the code

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.