# Help with \`Base.getproperty\` syntax

**URL:** <https://discourse.julialang.org/t/help-with-base-getproperty-syntax/16628>\
**Category:** General Usage\
**Created:** [October 22, 2018, 1:47pm UTC](https://discourse.julialang.org/t/help-with-base-getproperty-syntax/16628 "2018-10-22T13:47:36Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 22, 2018, 1:52pm UTC](https://discourse.julialang.org/t/help-with-base-getproperty-syntax/16628/2 "2018-10-22T13:52:57Z")

</div>

```julia
julia> struct S
           x
       end

julia> function Base.getproperty(x::S, sym::Symbol)
           if sym == :a
               "a"
           else
               # fallback to getfield
               getfield(x, sym)
           end
       end

julia> obj = S(1)
S(1)

julia> obj.a
"a"

julia> obj.x
1

julia> obj.y
ERROR: type S has no field y
Stacktrace:
 [1] getproperty(::S, ::Symbol) at ./REPL[2]:6

```

---

_[View the full topic](https://discourse.julialang.org/t/help-with-base-getproperty-syntax/16628)._
