Title: Is there a good reason not to allow direct access to properties whose name starts with a digit? · Issue #6946 · PowerShell/PowerShell · GitHub
Open Graph Title: Is there a good reason not to allow direct access to properties whose name starts with a digit? · Issue #6946 · PowerShell/PowerShell
X Title: Is there a good reason not to allow direct access to properties whose name starts with a digit? · Issue #6946 · PowerShell/PowerShell
Description: Currently, you cannot access an object's property if that property's name happens to start with a (decimal) digit: $obj = [pscustomobject] @{ '1a' = '1a''s value' } # !! BREAKS, because the property name starts with a digit. $obj.1a Note...
Open Graph Description: Currently, you cannot access an object's property if that property's name happens to start with a (decimal) digit: $obj = [pscustomobject] @{ '1a' = '1a''s value' } # !! BREAKS, because the propert...
X Description: Currently, you cannot access an object's property if that property's name happens to start with a (decimal) digit: $obj = [pscustomobject] @{ '1a' = '1a''s value' } ...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/6946
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Is there a good reason not to allow direct access to properties whose name starts with a digit?","articleBody":"Currently, you cannot access an object's property if that property's name happens to start with a (decimal) _digit_:\r\n\r\n```powershell\r\n$obj = [pscustomobject] @{ '1a' = '1a''s value' }\r\n \r\n # !! BREAKS, because the property name starts with a digit.\r\n$obj.1a\r\n```\r\n\r\nNote: It does work with an _all-digit name_, such as `111`, as explained below.\r\n\r\nThe error message you get is:\r\n\r\n```none\r\n...\r\nMissing property name after reference operator.\r\n...\r\n```\r\n\r\nThe current _workarounds_ are to either use _quoting_ or to _indirectly_ reference the property via a _variable_ containing the name:\r\n\r\n```powershell\r\n# OK: Quote the property name\r\n$obj.'1a'\r\n$obj.\"1a\"\r\n\r\n# OK: Access the property via a *variable*\r\n$propName = '1a'\r\n$obj.$propName\r\n```\r\n\r\n\u003csup>Note: `$obj.{1a}`, as mentioned by @george-chakhidze below, happens to work too, but it is an accidental by-product of script-block stringification.\r\n\u003c/sup>\r\n\r\n\r\nIs there a good reason _not_ to allow direct use of the literal property name?\r\nIn other words: why shouldn't `$obj.1a` work as-is?\r\n\r\n(By contrast, there are property names that do invariably require quoting, such as\r\n `([pscustomobject] @{ 'a.b' = 'a.b''s value' }).'a.b'`)\r\n\r\nEnvironment data\r\n----------------\r\n\r\nWritten as of:\r\n\r\n```powershell\r\nPowerShell Core v6.1.0-preview.2\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2018-05-27T23:30:50Z","url":"https://github.com/PowerShell/PowerShell/issues/6946"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:604054e6-0708-d18f-c1a3-c33e275dbc10 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8578:2BF055:ED86D3:154A5F5:6AFDA8C3 |
| html-safe-nonce | fd42d7447dbea22a4274b81bb61644f25f5125a9eaa5765c02b5f389c74a2082 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTc4OjJCRjA1NTpFRDg2RDM6MTU0QTVGNTo2QUZEQThDMyIsInZpc2l0b3JfaWQiOiIxNjY3NzA2NTAyNTY0OTE1Mzk1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a60c8d191bd9c2e5d63fd4efe9ab75e58131d75b278e2edd123e44a6d89db13c |
| hovercard-subject-tag | issue:326860869 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/6946/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e73801b39a9e0dab067a9b2fd322495b70ed10a3d0e9a2c8296bff06e2e3c671/PowerShell/PowerShell/issues/6946 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e73801b39a9e0dab067a9b2fd322495b70ed10a3d0e9a2c8296bff06e2e3c671/PowerShell/PowerShell/issues/6946 |
| og:image:alt | Currently, you cannot access an object's property if that property's name happens to start with a (decimal) digit: $obj = [pscustomobject] @{ '1a' = '1a''s value' } # !! BREAKS, because the propert... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | bc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0ddf53eb35c87f1f8df13dbf75c3bdadbfc6e969 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width