1

I'd like to access $user from the commandline to see what properties are available on it. I could sdpm($user) in my code and go inspect it in my browser, but isn't there a way I can inspect it right from my terminal?

It looks like drush php could be helpful here, according to http://blog.damiankloip.net/2015/drush-php, but when I use it and do dump -a $user I get 'Unknown variable: $user'. That's probably obvious, so I probably need to load $user into the repl first (I'm guessing)... but how? That blog post shows how to load objects in D8, but how would I do this in D7 for $user???

2

You need to define the $user variable first. You can run the drush command as a particular user by specifying --user on the command line:

drush --user='admin' ev 'global $user; print_r($user);'

If you don't specify a user, drush runs as anonymous by default.

Or, you can do it like this:

drush ev '$user = user_load_by_name("admin"); print_r($user);'

It will display this:

stdClass Object
(
    [uid] => 1
    [name] => admin
    [pass] => *****
    [mail] => info@example.com
    [theme] => 
    [signature] => 
    [signature_format] => filtered_html
    [created] => 1443708895
    [access] => 1515415027
    [login] => 1515411954
    [status] => 1
    [timezone] => Europe/London
    [language] => 
    [picture] => 0
    [init] => info@example.com
    [data] => 
    [uuid] => f6800524-c092-4abc-abcd-f71d091623cd
    [roles] => Array
        (
            [2] => authenticated user
        )

    [force_password_change] => 0
)
  • Excellent, and the second option was what I needed to get it to work in the repl with drush php. Thanks! – alec Feb 6 '18 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.