Title: PSCustomObject still has properties like Count and ForEach, even in strict mode · Issue #15526 · PowerShell/PowerShell · GitHub
Open Graph Title: PSCustomObject still has properties like Count and ForEach, even in strict mode · Issue #15526 · PowerShell/PowerShell
X Title: PSCustomObject still has properties like Count and ForEach, even in strict mode · Issue #15526 · PowerShell/PowerShell
Description: Steps to reproduce Set-StrictMode -Version Latest $object = [PSCustomObject]@{A=1; B=2; C=3; D=4; E=5} $object.Count # does not throw after version 6.1 More thorough repros/differences by version Expected behavior The error text below wh...
Open Graph Description: Steps to reproduce Set-StrictMode -Version Latest $object = [PSCustomObject]@{A=1; B=2; C=3; D=4; E=5} $object.Count # does not throw after version 6.1 More thorough repros/differences by version E...
X Description: Steps to reproduce Set-StrictMode -Version Latest $object = [PSCustomObject]@{A=1; B=2; C=3; D=4; E=5} $object.Count # does not throw after version 6.1 More thorough repros/differences by version E...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/15526
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PSCustomObject still has properties like Count and ForEach, even in strict mode","articleBody":"## Steps to reproduce\r\n\r\n```powershell\r\nSet-StrictMode -Version Latest\r\n\r\n$object = [PSCustomObject]@{A=1; B=2; C=3; D=4; E=5}\r\n$object.Count # does not throw after version 6.1\r\n```\r\n\r\n[More thorough repros/differences by version](https://www.pwsh-live-doc.com/pscustomobject#strict-mode)\r\n\r\n## Expected behavior\r\n\r\nThe error text below when trying to access the `Count` property.\r\n\r\n```none\r\nThe property 'Count' cannot be found on this object. Verify that the property exists.\r\n```\r\n\r\n## Actual behavior\r\n\r\nThe `Count` property returns the value of 1.\r\n\r\n```none\r\n1\r\n```\r\n\r\n## Environment data\r\n\r\n```none\r\nName Value\r\n---- -----\r\nPSVersion 7.1.3\r\nPSEdition Core\r\nGitCommitId 7.1.3\r\nOS Microsoft Windows 10.0.19042\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n\r\n## More detail\r\n\r\nBasically, one of the features of the latest version of strict mode is that trying to access non-existent properties on an object results in an exception. This includes properties like `Count`, which are available on all objects outside of strict mode.\r\n\r\nHowever, after #3671 was resolved, `PSCustomObject` no longer throws when you try to access `Count` in strict mode. The same is true for `Length`. This differs from the behavior of other objects such as numbers, strings, and process objects, which throw when `Count` is accessed.\r\n\r\nIf we want to follow #2798, then potentially the other objects like numbers should have their behavior changed. But as it stands, it seems like `PSCustomObject` is special in that it doesn't match the behavior of other types in strict mode.","author":{"url":"https://github.com/binyomen","@type":"Person","name":"binyomen"},"datePublished":"2021-06-05T04:05:57Z","url":"https://github.com/PowerShell/PowerShell/issues/15526"}
| 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:ad247a31-b2a6-560c-300f-ed22fcc1384d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D252:1A06F7:41AEA4:5C5181:6AFDC4A2 |
| html-safe-nonce | 9f7c53b4dae6e23a186e25d9a077b9ca2517b9664da1349d7777011af2979a85 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjUyOjFBMDZGNzo0MUFFQTQ6NUM1MTgxOjZBRkRDNEEyIiwidmlzaXRvcl9pZCI6Ijc4NTcwMTMyMTY1OTk5ODMyNjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4a95c06cf2dea73738558902a52129dbc068a90207afdea14bb6a558a5c8c25a |
| hovercard-subject-tag | issue:912093620 |
| 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/15526/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1e30c6553b15a4f2a766181dc31e5311b684e1a085d1d39eaaa70d69cfc2a7be/PowerShell/PowerShell/issues/15526 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1e30c6553b15a4f2a766181dc31e5311b684e1a085d1d39eaaa70d69cfc2a7be/PowerShell/PowerShell/issues/15526 |
| og:image:alt | Steps to reproduce Set-StrictMode -Version Latest $object = [PSCustomObject]@{A=1; B=2; C=3; D=4; E=5} $object.Count # does not throw after version 6.1 More thorough repros/differences by version E... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | binyomen |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9ab00cc3b4fa90bbd3da70765dd38efc23cfa9d9b0930e41feea2bf67f60ecaf |
| 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 | 1b795ba060b92691fc16c5a12cf2bf95e83432b4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width