Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CarlEOgden's avatar

Accessing .tag in PHP variable

Hi

I've got the following routine and I would like to know if the .tag = "folder" or not!

Any help on me fixing this:

                    $file = new \stdClass();

                    $file->id   = $dropbox_file->id;
                    $file->name = $dropbox_file->name;
                    $file->size = \StringHelpers::formatBytes($dropbox_file->size);
                    #$file->tag = $dropbox_file['.tag'];
                    if ($dropbox_file[".tag"] == 'folder') {
                        $file->tag = 'folder';
                    }else {
                        $file->tag = 'file';
                    }

I cannot get $dropbox_file['.tag'] or $dropbox_file[".tag"]

Thanks in advance Carl.

0 likes
6 replies
Sergiu17's avatar

Hi, so what is $dropbox_file? an object or an array?

$dropbox_file->id   // object
$dropbox_file->name // object
$dropbox_file->size // object
$dropbox_file[".tag"] // array
CarlEOgden's avatar

Hi

In all honesty I do not know!

I am working with a system someone else designed and built and has now left the company.

We are calling the dropbox api to get the directory listing so in this link:

https://www.dropbox.com/developers/documentation/http/documentation

And do a search for .tag you'll see that it is referenced around 725 times!

In most of them it's the first element in what you receive back and as it's described as ".tag" then all the rest of the variables don't seem to be in quotes or with . at the start of them!

Also, I'm struggling (due to lack of knowledge) on how to debug the variables, as this php routine is called when you click on a tab in the browser, it's made up of a template from within a blade (might even be within a blade) so we can never find the variable when we do a  @dd(get_defined_vars()); we never see the variable $file or fileList which is referenced!

I seem not to be able to get information from the php part but if I am editing the .js files, a simple console.error(variable) gives me what I want. Even doing a console.dir(window) in the console once the screen has draw doesn't get me the variable list I'd expect to see!

Hope the above doesn't confuse too much!

Cheers Carl.

CarlEOgden's avatar

Hi

I've got it working without crashing:

$file->tag = $dropbox_file->error[".tag"];

BUT, it comes back as an empty variable!

Ah Well! Onwards!

Carl.

hollyit's avatar

Do a dd($dropbox_file) and look at the output in the browser to see exactly what you're getting in that variable.

CarlEOgden's avatar

Hiya

Unfortunately, it's in a php file that doesn't seem to accept the existence of "dd" or "@dd" and so just crashes the function.

As this whole routine is built around a blade and then templates, it seems that the template can't be debugged at a level to get the results of either $dropbox_file or $file (the variable this routine returns to then display these variables). To a novice as I am, this is all very consfusing!

Debugging PHP vars is a pain!

All I've managed to work out with an isset is that $dropbox_file->error['.tag'] or even $dropbox_file->entries['.tag'] as this is what is listed as being returned in the dropbox api documentation.

Any help on other ideas of debugging php variables is welcome :)

Cheers Carl.

CarlEOgden's avatar
CarlEOgden
OP
Best Answer
Level 4

Solved it!

We have implemented this routine with an addon which excludes all the .tag attributes so I was chasing my tail!

Cheers Carl.

Please or to participate in this conversation.