PHP 5.6,Apache 2.4 | Windows 7,OpenServer
(static function () {
return true;
})();
为什么会抛出语法错误?
syntax error, unexpected '('
但是http://php.net/manual/en/functions.anonymous.php
PS:另外 - >通话也不起作用......(意外的' - >')
答案 0 :(得分:2)
这就是问题所在。它并不是静止的部分:
---
title: "Untitled"
author: "eipi10"
date: "February 12, 2017"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_knit$set(progress = FALSE, verbose = FALSE)
knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning=FALSE)
library(tidyverse)
library(scales)
library(knitr)
```
```{r}
# Adapted from http://stackoverflow.com/a/27234462/496488
kexpand <- function(ht, cap) {
cat(
knit(
text=knit_expand(
text=sprintf("```{r %s, fig.height=%s, fig.cap='%s'}\n .pl \n```", cap, ht, cap)
)))
}
```
```{r data}
df = structure(list(dept = c("English", "English", "English", "English",
"English", "English", "English", "English", "English", "English",
"English", "English", "English", "English", "English", "Biology",
"Biology", "Biology", "Biology", "Biology", "Biology", "Government",
"Government"), tot_enrl = c(114, 349, 325, 393, 415, 401, 166,
117, 302, 267, 256, 224, 481, 295, 122, 410, 478, 116, 278, 279,
238, 142, 145), course = c("ENGL 1", "ENGL 10M", "ENGL 11M",
"ENGL 16", "ENGL 1X", "ENGL 20M", "ENGL 3", "ENGL 30A", "ENGL 40A",
"ENGL 40B", "ENGL 50A", "ENGL 50B", "ENGL 5M", "ENGL 60", "ENGL 65",
"BIO 15L", "BIO 2", "BIO 30", "BIO 39", "BIO 7", "BIO 9", "GOVT 10",
"GOVT 1H")), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-23L), .Names = c("dept", "tot_enrl", "course"))
```
```{r results="asis"}
height.unit = 0.2
for (d in unique(df$dept)) {
.pl = ggplot(df[df$dept==d, ], aes(tot_enrl, reorder(course,tot_enrl))) + geom_point()
ht = height.unit * length(unique(df$course[df$dept==d])) + 1
kexpand(ht=ht, cap=d)
}
```
宣告和呼唤不起作用:
$f = static function () { return true; }; $f(); //Works in PHP 5.4+
问题是文档说第一种语法在PHP 5.4+中有效,但使用的是需要PHP 7+才能工作的示例。
答案 1 :(得分:1)