Access to undeclared static property

I’ve made a class in PHP and I’m getting a Fatal Error(Title) on the line marked with an asterisk(*)

I can’t figure out what’s causing it, also, the following class(same file) is returning the same error.

Do you happen to know what’s causing the error or how I can fix it?

Содержание
  1. 2 Answers 2
  2. 2 ответы
  3. Comments
  4. xqkeji commented May 2, 2017 •
  5. This comment has been minimized.
  6. xqkeji commented May 2, 2017 •
  7. This comment has been minimized.
  8. xqkeji commented May 2, 2017
  9. This comment has been minimized.
  10. Jurigag commented May 2, 2017
  11. This comment has been minimized.
  12. sergeyklay commented May 2, 2017 •
  13. This comment has been minimized.
  14. sergeyklay commented May 2, 2017
  15. This comment has been minimized.
  16. hakimio commented May 19, 2017
  17. This comment has been minimized.
  18. afbora commented Jul 28, 2017
  19. This comment has been minimized.
  20. sergeyklay commented Oct 28, 2017 •
  21. This comment has been minimized.
  22. sergeyklay commented Oct 28, 2017
  23. This comment has been minimized.
  24. Jurigag commented Oct 28, 2017
  25. This comment has been minimized.
  26. xqkeji commented Nov 19, 2017 •
  27. This comment has been minimized.
  28. mattratcliffe86 commented Jan 16, 2018 •
  29. This comment has been minimized.
  30. hakimio commented Jan 16, 2018 •
  31. This comment has been minimized.
  32. mattratcliffe86 commented Jan 16, 2018
  33. This comment has been minimized.
  34. hakimio commented Jan 16, 2018
  35. This comment has been minimized.
  36. Pilsenerek commented Feb 4, 2018
  37. This comment has been minimized.
  38. hakimio commented Feb 4, 2018 •
  39. This comment has been minimized.
  40. sergeyklay commented Feb 27, 2018
  41. This comment has been minimized.
  42. hakimio commented Feb 27, 2018 •
  43. This comment has been minimized.
  44. sergeyklay commented Mar 1, 2018 •
  45. This comment has been minimized.
  46. hakimio commented Mar 1, 2018
  47. This comment has been minimized.
  48. mattratcliffe86 commented Mar 1, 2018 •

2 Answers 2

You should declare your properties with keyword static, e.g.

Use $this-> instead of self::

Self is for static members and $this is for instance variables.

November 2018

27.7k раз

Я сделал класс в PHP, и я получаю фатальную ошибку (название) на линии, помеченные звездочкой (*)

Я не могу понять, чем это вызвано, также, следующий класс (тот же файл) возвращает ту же ошибку.

Вы случайно не знаете, что вызывает ошибку или как я могу это исправить?

2 ответы

Вы должны объявить свои свойства с ключевым словом статическими, например,

Используйте $this-> вместо self::

Self для статических членов и $this для переменных экземпляра.

Comments

Copy link Quote reply

xqkeji commented May 2, 2017 •

When ajax request more than 3 times, there will be "Access to undeclared static property"
E.g

in window php7.0 ts

This comment has been minimized.

Copy link Quote reply

xqkeji commented May 2, 2017 •

Does php7 do not need TSRMLS_CC

This comment has been minimized.

Copy link Quote reply

xqkeji commented May 2, 2017

As long as the load is high, will appear "Access to undeclared static property"。

This comment has been minimized.

Copy link Quote reply

Jurigag commented May 2, 2017

Add that this happens only on php apache module, on cli or fpm it works fine and without issues.

This comment has been minimized.

Copy link Quote reply

sergeyklay commented May 2, 2017 •

This comment has been minimized.

Copy link Quote reply

sergeyklay commented May 2, 2017

@sjinks Could you please take a look

This comment has been minimized.

Copy link Quote reply

hakimio commented May 19, 2017

@sjinks It’s rather important that you take a look at this bug as soon as possible, because it prevents usage of thread-safe extension on any platform, not only windows. So, it’s no longer possible to use phalcon with pthreads and similar stuff which actually requires thread safety.

This comment has been minimized.

Copy link Quote reply

afbora commented Jul 28, 2017

I got this error on Phalcon 3.2.0 today.
Its gone when i refresh the page 😕

This comment has been minimized.

Copy link Quote reply

sergeyklay commented Oct 28, 2017 •

@php318 Could you change your code to:

This comment has been minimized.

Copy link Quote reply

sergeyklay commented Oct 28, 2017

This comment has been minimized.

Copy link Quote reply

Jurigag commented Oct 28, 2017

@sergeyklay i saw you are doing some tests with this, are you sure you are doing it on TS php? Beacause as i remember this is main issue, but not sure.

This comment has been minimized.

Copy link Quote reply

xqkeji commented Nov 19, 2017 •

@sergeyklay
I test it, the error still exists.

This comment has been minimized.

Copy link Quote reply

mattratcliffe86 commented Jan 16, 2018 •

Hey guys, what was the outcome to this bug?

I’m encountering the same issue on Windows and Apache 2.4 running PHP 7.1.1 and Phalcon 3.2.4

This comment has been minimized.

Copy link Quote reply

hakimio commented Jan 16, 2018 •

This comment has been minimized.

Copy link Quote reply

mattratcliffe86 commented Jan 16, 2018

@hakimio Thanks for that.

So this is specifically affecting the thread safe extension for Apache, just on Windows or is it Linux too?

This comment has been minimized.

Copy link Quote reply

hakimio commented Jan 16, 2018

@mattratcliffe86 It’s effecting both windows and linux thread-safe extensions.

This comment has been minimized.

Copy link Quote reply

Pilsenerek commented Feb 4, 2018

I have the same problem:
Phalcon 3.3.1
System Win7
PHP:

  • version 7.2
  • tread safe enabled
  • architecture x86
  • compiler MSVC15

It occurs especially when there are many requests in the same time or fast one by one in row.

This comment has been minimized.

Copy link Quote reply

hakimio commented Feb 4, 2018 •

@Pilsenerek
Its’s an old well-known issue. See the following: phalcon/cphalcon#12056

This comment has been minimized.

Copy link Quote reply

sergeyklay commented Feb 27, 2018

I’m going to solve this issue so I need code to reproduce guys. Could someone provide a worked (badly) example?

This comment has been minimized.

Copy link Quote reply

hakimio commented Feb 27, 2018 •

@sergeyklay It’s rather easy to reproduce the issue. You just need to run phalcon Thread-Safe extension with Apache on Windows (some people reported the issue on Linux as well but I’ve never tried running Phalcon TS on Linux personally) and then just make a large number of parallel requests (shouldn’t need more than a 100) to a single end-point which does some simulated work ("usleep(100000)" should work just fine).

This comment has been minimized.

Copy link Quote reply

sergeyklay commented Mar 1, 2018 •

I need to locate problem. So it is too complex to use full framework to debug this. Actually I need an example as small as possible

This comment has been minimized.

Copy link Quote reply

hakimio commented Mar 1, 2018

Maybe then create a simple Zephir extension, compile it with TS and use pthreads to check if it is actually thread safe?

This comment has been minimized.

Copy link Quote reply

mattratcliffe86 commented Mar 1, 2018 •

Quick and dirty way to reproduce the error.
ptest.zip

I’ve created a controller ‘reload’ which just reloads the page a given number of times and increments the value in the url segment by 1 each time. I’m redirecting, which is what I did when I first encountered the problem. Same thing occurs when you use $response->redirect() (PhalconHttpResponse) or the native header() function in PHP.

PHP Fatal error: Uncaught Error: Access to undeclared static property PhalconDi::$_default in index.php on line 10

Line 10 happens to be $di = new FactoryDefault();

Оцените статью
Много толка
Добавить комментарий