Can an AJAX callback function access a PHP variable which was defined during initial page load?

Based on comments in this thread, I think using a WordPress transient to store the value of $myvar is the best solution in my case. One reason is because in my case, the browser does not need to know the value of the variable.

Here is some more information to make an informed decision in your specific use case:

  • This separate Stack Exchange question has an answer which provides more information on all the ways to persist data in WordPress, including the use of transients.
  • This link has more info on specific options.
  • PHP sessions don’t seem to be suggested for WordPress uses (see the previous two links). But this link has more info on them.