Jump to content

stdClass() PW equivalent


fruid
 Share

Recommended Posts

I have to use the php standard class stdClass for my function to work. But that doesn't work in the Processwire namespace. What's the equivalent in Processwire? I think it's the best bet to find an equivalent API instead of going in and out of different namespaces.

Link to comment
Share on other sites

Put a backslash in front if you want to use PHP classes, or am I missing something?

It’s near impossible to answer your question without knowing why you want to use stdClass. Could well be that ProcessWire has something suitable for your use case, but what is your use case?

  • Like 1
Link to comment
Share on other sites

Yes, in a file with namespace ProcessWire that will let you use it:

$foo = new \stdClass();

You can also put “use \stdClass” at the top if you need it a lot.

The same goes for all the other stuff outside PW’s namespace. Often you’ll need \DateTime or \IntlDateFormatter for example.

Edit: the technical term is “The Global Space”: https://www.php.net/manual/en/language.namespaces.global.php

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...