php-7

Anonymous class construction

…衆ロ難τιáo~ 提交于 2020-01-02 01:47:10
问题 I need an idea to create anonymous class on PHP. I don't know how I can works. See my limitations : On PHP you can't make anonymous class, like anonymous function (like class {} ); On PHP you don't have class scope (except in namespaces, but it have the same problem below); On PHP you can't use variables to specify the class name (like class $name {} ); I don't have access to install the runkit PECL. What I need, and why : Well, I need create a function called ie create_class() that receives

Laravel 5.4 TokenMismatchException in VerifyCsrfToken.php line 68 on some device

别等时光非礼了梦想. 提交于 2020-01-01 19:36:59
问题 I know it's one of the most asked question around here, but I really read everything on the first 10 pages results on google and nothing solved my problem. On a fresh installation of laravel 5.4 , generated the auth controller, views, etc. via php artisan make:auth when I try to register (or login) in some device I get the following error: TokenMismatchException in VerifyCsrfToken.php line 68 I'm running this application in local on debian 8.7 and php7 (could it be related to the problem in

Laravel 5.4 TokenMismatchException in VerifyCsrfToken.php line 68 on some device

 ̄綄美尐妖づ 提交于 2020-01-01 19:36:30
问题 I know it's one of the most asked question around here, but I really read everything on the first 10 pages results on google and nothing solved my problem. On a fresh installation of laravel 5.4 , generated the auth controller, views, etc. via php artisan make:auth when I try to register (or login) in some device I get the following error: TokenMismatchException in VerifyCsrfToken.php line 68 I'm running this application in local on debian 8.7 and php7 (could it be related to the problem in

Variable variables handling order: changes in PHP 7

天大地大妈咪最大 提交于 2020-01-01 19:07:29
问题 With the new PHP 7.0.0 out now, I'm a bit worried about the changes in evaluation order of the so-called 'variable variables'. On this page, under 'Changes to variable handling', a table is displayed with examples of expressions with their handling order in PHP 5 and PHP 7. The four expressions listed are: $$foo['bar']['baz'] $foo->$bar['baz'] $foo->$bar['baz']() Foo::$bar['baz']() Given the following string and array: $qux = 'quux'; $foo = array('bar' => array('baz' => 'qux')); the first

Why I am suddenly getting a “Typed property must not be accessed before initialization” error when introducing properties type hints?

a 夏天 提交于 2019-12-31 02:22:05
问题 I have updated my class definitions to make use of the newly introduced property type hints, like this: class Foo { private int $id; private ?string $val; private DateTimeInterface $createdAt; private ?DateTimeInterface $updatedAt; public function __construct(int $id) { $this->id = $id; } public function getId(): int { return $this->id; } public function getVal(): ?string { return $this->val; } public function getCreatedAt(): ?DateTimeInterface { return $this->createdAt; } public function

What type hint to use if return value is mixed?

北城以北 提交于 2019-12-30 11:31:58
问题 function foo ($a): mixed { if ($a == 1) return true; else return 'foo'; } var_dump(foo(1)); Since mixed is not a real type this results to: Fatal error: Uncaught TypeError: Return value of foo() must be an instance of mixed... Is there a way to type hint a mixed return value or do you simply not declare type hints in this type of scenario? 回答1: Type hints are there to enforce some restriction on the value passed or returned. Since "mixed" would allow any value at all, its use as a type hint

PHP 7 with phpmyadmin gives lots of Deprecation Notices

余生颓废 提交于 2019-12-29 10:13:13
问题 I have Ubuntu 16.04 LTS running with PHP7 and phpmyadmin installed. However, I get a lot of deprecation notices like: Deprecation Notice in ./../php/php-gettext/streams.php#48 Methods with the same name as their class will not be constructors in a future version of PHP; StringReader has a deprecated constructor Backtrace ./../php/php-gettext/gettext.inc#41: require() ./libraries/select_lang.lib.php#477: require_once(./../php/php-gettext/gettext.inc) ./libraries/common.inc.php#569: require(.

C#'s null coalescing operator (??) in PHP

岁酱吖の 提交于 2019-12-27 23:37:07
问题 Is there a ternary operator or the like in PHP that acts like ?? of C#? ?? in C# is clean and shorter, but in PHP you have to do something like: // This is absolutely okay except that $_REQUEST['test'] is kind of redundant. echo isset($_REQUEST['test'])? $_REQUEST['test'] : 'hi'; // This is perfect! Shorter and cleaner, but only in this situation. echo null? : 'replacement if empty'; // This line gives error when $_REQUEST['test'] is NOT set. echo $_REQUEST['test']?: 'hi'; 回答1: PHP 7 adds the

How to extend femanager controller under php 7

删除回忆录丶 提交于 2019-12-25 08:58:57
问题 Since using PHP 7.0 and higher, the strict mode of php generates warnings like this: PHP Warning: Declaration of In2code\Femanagerextended\Controller\EditController::updateAction(In2code\Femanagerextended\Domain\Model\User $user) should be compatible with In2code\Femanager\Controller\EditController::updateAction(In2code\Femanager\Domain\Model\User $user) in ($PATH)\typo3conf\ext\femanagerextended\Classes\Controller\EditController.php line 17 when trying to extend an existing controller of the

PHP7 can't connect to MySQL

点点圈 提交于 2019-12-24 10:59:26
问题 The following code had worked on PHP5 and MySQL5.6. Under Kubuntu and Windows. In this particular case I'm trying to run it under Kubuntu 16.04 PHP7 and MySQL5.7. Connection to database can not be established. There is no error message, the execution ends with the row for connection to base, and as a result report_before from the code is typed, but report_after is not. <?php echo "<form id='login' action='' method='POST' accept-charset='UTF-8'>"; echo "<input type='password' name='password'