I dont think its possible to get that effect without using transparency.
With a depth buffer you only have whats in the front, not the back. This will work only for one object using the buffer, and sampling the other in the standar depth, wich is odd and problematic in many cases. But nontheless it will work if you only want the sphere to be visible behind objects.