Skip to content

Commit

Permalink
Match PHP's use strict; easter egg and add one of our own
Browse files Browse the repository at this point in the history
Summary: It's all fun and games...

Closes #4556

Reviewed By: @fredemmott

Differential Revision: D1860928
  • Loading branch information
sgolemon authored and hhvm-bot committed Feb 20, 2015
1 parent fb09e0d commit 55eb45f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions hphp/compiler/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,15 @@ void Parser::onNamespaceEnd() {
}

void Parser::onUse(const std::string &ns, const std::string &as) {
if (ns == "strict") {
if (m_scanner.isHHSyntaxEnabled()) {
error("To use strict hack, place // strict after the open tag. "
"If it's already there, remove this line. "
"Hack is strict already.");
}
error("You seem to be trying to use a different language. "
"May I recommend Hack? http://hacklang.org");
}
string key = fully_qualified_name_as_alias_key(ns, as);

// It's not an error if the alias already exists but is auto-imported.
Expand Down
5 changes: 5 additions & 0 deletions hphp/test/slow/parser/use-strict-hack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?hh

use strict;

echo "Done";
1 change: 1 addition & 0 deletions hphp/test/slow/parser/use-strict-hack.php.expectf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fatal error: To use strict hack, place // strict after the open tag. If it's already there, remove this line. Hack is strict already. in %s/test/slow/parser/use-strict-hack.php on line 3
5 changes: 5 additions & 0 deletions hphp/test/slow/parser/use-strict.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

use strict;

echo "Done";
1 change: 1 addition & 0 deletions hphp/test/slow/parser/use-strict.php.expectf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fatal error: You seem to be trying to use a different language. May I recommend Hack? http://hacklang.org in %s/test/slow/parser/use-strict.php on line 3

5 comments on commit 55eb45f

@Majkl578
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how exactly does this differ from #4643, which I abandoned because it was incorrect?

@marcioAlmada
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==> "May I recommend Hack? http://hacklang.org"

@Majkl578
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And? It's still wrong, it doesn't address the issues mentioned in Phabricator...

@fredemmott
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @sgolemon , yep still looks wrong

@Majkl578
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump

Please sign in to comment.