0

I have a PHP file where I am wondering if there is a way to replace ArrayObject with something else? I have the following:

    for ($i = 0; $i <sizeof($compO); ++$i) {
        $cpO[] = self::equal_array($compO[$i]);
           I do a bunch of stuff here
    }

    protected static function equal_array($arr){
        $arrayObject = new ArrayObject($arr);
        return $arrayObject->getArrayCopy();
     }

For some reason, the new ArrayObject call in equal_array() is giving me an error that indicates that ArrayObject is not in the namespace. Is there a way to replace the equal_array function with something equivalent or is there a way to correct the namespace problem? I thought ArrayObject was part of PHP so not sure why it isn't found in the namespace.

1
  • 3
    try new \ArrayObject() Commented Jun 27, 2018 at 18:42

1 Answer 1

1

Add

use ArrayObject;

after setting the namespace of your file.

Sign up to request clarification or add additional context in comments.

2 Comments

this may have worked...I have a bit of testing to do but at least so far I don't get the same error so I am very hopeful. I just would've thought I wouldn't need to do that as I would have thought it was already part of PHP and so would've been included...guess not. THANKS!
Builtin classes are in the global namespace \ArrayObject

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.