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

  • SEARCH
  • Home
  • 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 7811613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:13:47+00:00 2026-06-02T04:13:47+00:00

I use namespace for a class like this below, class_tidy.php, namespace foo; class tidy

  • 0

I use namespace for a class like this below,

class_tidy.php,

namespace foo;

class tidy {
    public function hello() {
        echo 'Hello';
    }
}

index.php,

class MyAutoloader
{
    public static function load($className)
    {
        $parts = explode('\\', $className);
        require 'classes/class_'.end($parts) . '.php';
    }
}

spl_autoload_register("\MyAutoloader::load");

$test = new foo\tidy();
$test->hello();

It works perfectly, but I wonder if I can access the class, instead of,

$test = new foo\tidy();

But,

$test = new foo::tidy(); 

Which looks prettier. but with this error,

Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE
or ‘$’ …

  • 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-06-02T04:13:48+00:00Added an answer on June 2, 2026 at 4:13 am

    You can’t. The PHP syntax uses \ for namespaces.

    As a matter of fact, php uses the T_PAAMAYIM_NEKUDOTAYIM (which is their name for the double colon) for only one thing, using it after a class name to specify you want a member of that class.

    I do believe there are some obscure details in the way this works which prevented PHP from using it as the namespace sperator as well, but I do not know which. (The thing is that this would mean that even if you branched from the official php and made your own version, you would have to go through a lot of work just to get that slight syntax change you want.)

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

Sidebar

Related Questions

I have a class like this: [Serializable] public class Structure { #region Constants and
The code looks like below: namespace Test { public interface IMyClass { List<IMyClass> GetList();
Let's say I have a class defined something like the below: namespace MyProject.MyConstants {
ValidateGatherType.php namespace D2E\CoreBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; class ValidateGatherType extends
Given these classes: using System.Collections.Generic; namespace FluentMappingsQuestion { public class Entity { public virtual
Assuming an XML like this: <my:Root xmlns:my=http://foo/bar> <my:FieldBasic>content</my:FieldBasic> <my:FieldComplex> <html xml:space=preserve xmlns=http://www.w3.org/1999/xhtml> <div><h1>content</h1></div> </html>
If I import a namespace like this: using System; Why can't I access subnamespace
namespace myobjects { class mylifeforms { public enum Animal { dog, cat, mouse }
I have a class ComponentItem which i simplified (pseudo code) below public class ComponentItem
I have the code below: namespace WindowMover { using System.Windows.Forms; static class Logic {

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.