Quantcast
Channel: Question and Answer » variables
Browsing latest articles
Browse All 37 View Live

What is the use case for shadowing variables?

One of the things the coffeescript programming language is criticized for is its treatment of variable declarations and scope (example). The answers to this question (and the blog I linked to above)...

View Article


Avoid This Pointer

PROBLEM: this points to different instances at different stages of execution (as it should). But it is not always obvious which instance is that. On the other hand we could minimize the use of this,...

View Article


Dynamically adding filters

I have a function that I’m trying to get an array in it to use in a callback to dynamically add filters. Here is the function that I need to retrieve the array keys from ( in the $classes variable ):...

View Article

Get WordPress Page Title, ID, or Template of the Page an AJAX Request is Made...

I have a page template that includes a region that holds links to a series of video custom post types. Each of the links is tagged with an ‘ajax-link’ class so that through an AJAX request I can pull...

View Article

Image may be NSFW.
Clik here to view.

What is internal state and is there a difference between state and internal...

Ok, this question has been asked before, but it’s still not clear to me. What exactly is internal state? So far state is clear to me: Functions contain behavior, variables have state, values don’t. So...

View Article


What is the impact of re-defining a dynamic type variable (such as in PHP)?

PHP variables are dynamic in type so I can do: $x = 'hello world!'; $x = strlen($x); Sometimes this is trivial and I could save many lines of code, but it reduces clarity. I’m using a text editor, but...

View Article

ACF allow zero as a value

I would like to have 0 to 5, and “n/a” as possible values, however this code will output “n/a” when I want it to output a zero. How can I get it to output “0″? (“n/a” is the placeholder if no value is...

View Article

Can't access a variable defined in another template despite using GLOBAL

I created, populated and successfully echoed a variable x in header.php. Then in my front page template I did global $x then echo $x. This displays nothing. Why?

View Article


Passing variable from child theme function to parent theme filter

I want to pass a variable from my child theme function to a filter which resides in my parent theme. Please let me know whether below code will work or not ? Is it the right way ? Code in Parent...

View Article


Using variable in two functions

What would be the right way of using variable with same data in two functions? Is next approach good practice? I have a few of these variables set up in functions.php $a = array('asdf', 'asdf',...

View Article
Browsing latest articles
Browse All 37 View Live