The variance is evaluated at the NULL p0, not at the estimate, which is why the score test still works when phat is 0 or 1.
References
Rao (1948), Mathematical Proceedings of the Cambridge Philosophical Society 44(1), 50-57 – the primary source for the score test. Wasserman (2004), All of Statistics, does not give the score test, so it is not cited for this formula.
Examples
Scoretest(successes = 5L, n = 5L)
#> $statistic
#> [1] 2.236068
#>
#> $chisq
#> [1] 5
#>
#> $p_value
#> [1] 0.02534732
#>
#> $estimate
#> [1] 1
#>
#> $se_null
#> [1] 1.118034
#>
#> $n
#> [1] 5
#>
#> $method
#> [1] "Rao score test for a binomial proportion"
#>
#> attr(,"class")
#> [1] "morie_rich_result" "list"
