Home >Backend Development >PHP Tutorial >thinkphp object-oriented problem
At the beginning of the TP framework paging class, I saw a private attribute private $url = '';
I saw that this private attribute is used in two places below.
This private method is here Above the show method, when running this private method, the $url attribute is empty. Will there be no error?
<code>private function url($page){ return str_replace(urlencode('[PAGE]'), $page, $this->url); } public function show() { if(0 == $this->totalRows) return ''; $this->parameter[$this->p] = '[PAGE]'; $this->url = U(ACTION_NAME, $this->parameter); ……</code>
At the beginning of the TP framework paging class, I saw a private attribute private $url = '';
I saw that this private attribute is used in two places below.
This private method is here Above the show method, when running this private method, the $url attribute is empty. Will there be no error?
<code>private function url($page){ return str_replace(urlencode('[PAGE]'), $page, $this->url); } public function show() { if(0 == $this->totalRows) return ''; $this->parameter[$this->p] = '[PAGE]'; $this->url = U(ACTION_NAME, $this->parameter); ……</code>
Are you sure you understand programming?
All functions have two processes: definition and calling. What you see are two definition processes.
The use of variables in the definition process does not actually use the variables, the variables are used in the calling process.
So the order of definition does not affect the value of the variable, so why is there any distinction between top and bottom.
The description of the str_replace function says: This function is binary safe.
Binary security, from my understanding, can correctly handle any input byte, even if it contains zero-value bytes. The questioner can also search for the concept of binary security
Is your url a private property or a private method?
The private attribute $this->url is defined in your show method and will not be empty
What are these answers? . . Halo, are you a programmer?
First of all, it is a class, and what you call is not a static function, so the url is initialized when the class instance is created. It is '', an empty string. It is not undefined, it is defined but empty. So there will be no error.